I try to catch text by Regular Expression. I list codes as follows.
Pattern p=Pattern.compile("<@a>(?:.|\\s)+?</@a>");
Matcher m = p.matcher(fileContents.toString());
while(m.find()) {
//Error will be thrown at this point
System.out.println(m.group());
}
If the length of text I want to catch is too long, system will throw me a StackOverflowError.
Otherwise, the codes work well.
Please help me how to solve this problem.
The dot and
\sboth match whitespace characters. That might lead to unnecessary backtracking. What do you want to match? Probably any character, including linebreaks?Then just use the lazy dot with the dot-matches-newlines option enabled:
You are aware that you’ll run into trouble if
<@a>tags can be nested in your input?