In javascript and/or node.js, how to write a regular expression for the following purpose:
1) The text must contain at least one line and must not exceed 10000 lines.
2) Each line is made up of a string followed by an integer. The string alphabet is limited to "ACGTN", and its length must be at least 1 and at most 64. The integer must be within 0 to 9, i.e. length must be 1.
Here is an valid example:
ACCCGTTNNGTCCGGA3
ACCCGTTNNGTCCGGATTGAANNGT9
TTGGACCNAC0
Here is an invalid example: (contains out-of-alphabet character)
BACGGTA0
Another invalid example: (no integer at the second line)
ACGGTA0
TTGGACCNAC
Another invalid example: (string longer than 64 characters)
TTGGACCNACACCCGTTNNGTCCGGATTGAANNGTTTGGACCNACACCCGTTNNGTCCGGATTGAANNGTTTGGACCNACACCCGTTNNGTCCGGATTGAANNGT2
Regex, to the rescue:
^[ACGTN]{1,64}\d$
Just split the input up by the \n
(newline character) and test each line against this regex.
If you want to validate all the file using a regular expression, use this one:
^([ACGTN]{1,64}\d\n){0,9999}[ACGTN]{1,64}\d$
Blender's answer is good too, but it is only for one line