Stack Overflow Problmen - reformat regular expression
"Ulla (Ulrike) Schat" <[email protected]> Wed, 11 Feb 2004 10:26:03 +0100
| Newsgroups | gmane.comp.jakarta.oro.user |
|---|---|
| Message-ID | <[email protected]> |
Hello,
I am using Oro 2.0.1. I get a StackOverflowError and it looks to me like
the problem that was described in the Thread "Stack Overflow Problem"
and in bug 3561. There it is described that the problem is caused by the
regular expression and can be solved by changing that expression.
I tried several changes for the regular expressions but I always got the
following StackOverflowError if the input String is quite long (see
attached test program):
java.lang.StackOverflowError
at java.util.Vector.addElement(Vector.java:584)
at java.util.Stack.push(Stack.java:44)
at
org.apache.oro.text.regex.Perl5Matcher.__pushState(Perl5Matcher.java:162)
at org.apache.oro.text.regex.Perl5Matcher.__match(Perl5Matcher.java:1012)
at org.apache.oro.text.regex.Perl5Matcher.__match(Perl5Matcher.java:1015)
at org.apache.oro.text.regex.Perl5Matcher.__match(Perl5Matcher.java:1015)
....
....
[many of these, all in line 1015]
This is the original regular expression: {(\\d+):(([^}](?!-}))*)
I would like to get
1. the character(s) after { and before :
2. the rest of the String after : until there is "}" which should not be
included and until there is "-}" which should also not be included.
In the input String, "-}" is always preceded by "\r\n". For me, it does
not make a difference if the result contains these ending "\r\n" or not.
With these changes I also got the same problem:
{(\\d+):(([^-}]|-(?!}))*)
{(\\d+):((-(?!})|[^-}])*)
{(\\d+):(([\\w/?:().,'+{\\r\\n -](?!-}))*)
The last one also works fine with a short input String since I know that
I only expect those characters.
Thanks a lot for any help or advice about how to reformat the regular
expression so it can also deal with long input Strings!
Ulla
This is my little test program:
import org.apache.oro.text.regex.*;
public class TestRegexp {
public static void main(String[] args) {
String input_long = "{1:\r\n" +
"this is some more text - and some more and some more and even
more\r\n" +
"this is some more text and some more and some more and even
more\r\n" +
"this is some more text and some more and some more and even
more\r\n" +
"this is some more text and some more and some more and even
more\r\n" +
"this is some more text and some more and some more and even
more\r\n" +
"this is some more text and some more and some more and even
more\r\n" +
"this is some more text and some more and some more and even
more\r\n" +
"this is some more text and some more and some more and even
more\r\n" +
"this is some more text and some more and some more and even
more\r\n" +
"this is some more text and some more and some more and even
more\r\n" +
"this is some more text and some more and some more and even
more\r\n" +
"this is some more text and some more and some more and even
more\r\n" +
"this is some more text and some more and some more and even
more\r\n" +
"this is some more text and some more and some more and even
more\r\n" +
"this is some more text and some more and some more and even
more\r\n" +
"this is some more text and some more and some more and even
more\r\n" +
"this is some more text and some more and some more and even
more\r\n" +
"this is some more text and some more and some more and even
more\r\n" +
"this is some more text and some more and some more and even
more\r\n" +
"this is some more text and some more and some more and even
more\r\n" +
"this is some more text and some more and some more and even
more\r\n" +
"this is some more text and some more and some more and even
more\r\n" +
"this is some more text and some more and some more and even
more\r\n" +
"this is some more text and some more and some more and even
more\r\n" +
"this is some more text and some more and some more and even
more\r\n" +
"this is some more text and some more and some more and even
more\r\n" +
"this is some more text and some more and some more and even
more\r\n" +
"this is some more text and some more and some more and even
more\r\n" +
"this is some more text and some more and some more and even
more\r\n" +
"this is some more text and some more and some more and even
more\r\n" +
"this is some more text and some more and some more and even
more\r\n" +
"this is some more text and some more and some more and even
more\r\n" +
"this is some more text and some more and some more and even
more\r\n" +
"this is some more text and some more and some more and even
more\r\n" +
"this is some more text and some more and some more and even
more\r\n" +
"this is some more text and some more and some more and even
more\r\n" +
"this is some more text and some more and some more and even
more\r\n" +
"this is some more text and some more and some more and even
more\r\n" +
"this is some more text and some more and some more and even
more\r\n" +
"this is some more text and some more and some more and even
more\r\n" +
"this is some more text and some more and some more and even
more\r\n" +
"this is some more text and some more and some more and even
more at the end\r\n" +
"-}";
String regexp_pattern = "{(\\d+):(([^}](?!-}))*)";
Perl5Matcher _matcher = new Perl5Matcher();
Perl5Compiler _compiler = new Perl5Compiler();
Pattern _pattern = null;
PatternMatcherInput pmInput = null;
MatchResult mr = null;
try {
_pattern = _compiler.compile(regexp_pattern,
Perl5Compiler.SINGLELINE_MASK);
}
catch (MalformedPatternException e) {
e.printStackTrace();
}
pmInput = new PatternMatcherInput(input_long);
if (_matcher.contains(pmInput, _pattern)) {
mr = _matcher.getMatch();
for (int idx = 1; idx < mr.groups(); idx +=1) {
System.out.println("value[" + idx + "] = '" +
mr.group(idx) + "'");
}
}
}
}