I am attempting to use a regular expression with Scanner to match a string from a file. The regex works with all of the contents of the file except for this line:
DNA="ITTTAITATIATYAAAYIYI[....]ITYTYITTIYAIAIYIT"
in the actual file, the ellipsis represents several thousand more characters.
When the loop that reads the file arrives on the line containing the bases, a stack overflow error occurs.
Here is the loop:
while (scanFile.hasNextLine()) {
final String currentLine = scanFile.findInLine(".*");
System.out.println("trying to match '" + currentLine + "'");
Scanner internalScanner = new Scanner(currentLine);
String matchResult = internalScanner.findInLine(Constants.ANIMAL_INFO_REGEX);
assert matchResult != null : "there's no reason not to find a match";
matches.put(internalScanner.match().group(1), internalScanner.match().group(2));
scanFile.nextLine();
}
and the regex:
static final String ANIMAL_INFO_REGEX = "([a-zA-Z]+) *= *\"(([a-zA-Z_.]| |\\.)+)";
Here's the failure trace:
java.lang.StackOverflowError
at java.util.regex.Pattern$CharProperty.match(Pattern.java:3360)
at java.util.regex.Pattern$Branch.match(Pattern.java:4131)
at java.util.regex.Pattern$GroupHead.match(Pattern.java:4185)
at java.util.regex.Pattern$Loop.match(Pattern.java:4312)
at java.util.regex.Pattern$GroupTail.match(Pattern.java:4244)
at java.util.regex.Pattern$BranchConn.match(Pattern.java:4095)
at java.util.regex.Pattern$CharProperty.match(Pattern.java:3362)
at java.util.regex.Pattern$Branch.match(Pattern.java:4131)
at java.util.regex.Pattern$GroupHead.match(Pattern.java:4185)
at java.util.regex.Pattern$Loop.match(Pattern.java:4312)
at java.util.regex.Pattern$GroupTail.match(Pattern.java:4244)
at java.util.regex.Pattern$BranchConn.match(Pattern.java:4095)
at java.util.regex.Pattern$CharProperty.match(Pattern.java:3362)
at java.util.regex.Pattern$Branch.match(Pattern.java:4131)
at java.util.regex.Pattern$GroupHead.match(Pattern.java:4185)
at java.util.regex.Pattern$Loop.match(Pattern.java:4312)
at java.util.regex.Pattern$GroupTail.match(Pattern.java:4244)
at java.util.regex.Pattern$BranchConn.match(Pattern.java:4095)
...etc (it's all regex).
Thanks so much!