I have an following program, that leads to java.lang.StackOverflowError
import org.apache.regexp.RE;

public class RegexpTest {

        public static void main(String[] args) {
                System.out.println("START");

                String str = 
"506c61746261207a61206eec636f20646f737420646f6272fd686f"+
                "506c61746261207a61206eec636f20646f737420646f6272fd686f"+
"506c61746261207a61206eec636f20646f737420646f6272fd686f"
+"506c61746261207a61206eec636f20646f737420646f6272fd686f"
+"506c61746261207a61206eec636f20646f737420646f6272fd686f"
+"506c61746261207a61206eec636f20646f737420646f6272fd686f"
+"506c61746261207a61206eec636f20646f737420646f6272fd686f"
+"506c61746261207a61206eec636f20646f737420646f6272fd686f"
+"506c61746261207a61206eec636f20646f737420646f6272fd686f"
+"506c61746261207a61206eec636f20646f737420646f6272fd686f"
+"506c61746261207a61206eec636f20646f737420646f6272fd686f"
+"506c61746261207a61206eec636f20646f737420646f6272fd686f"
+"506c61746261207a61206eec636f20646f737420646f6272fd686f"
+"506c61746261207a61206eec636f20646f737420646f6272fd686f";

                String regexpString = 
"(((([:alpha:]|[:digit:])+)\\.){1,2})"; // <-- almost smallest construction, that 
leads to problems 
                
        
                for (int i = 0; i < str.length(); i+=10) {
                        String sub = str.substring(0, i);
                        RE r = new RE(regexpString);
                        long ts = System.currentTimeMillis();
                        r.match(sub);
                        System.out.println("Matching [" + i + "] TIME: " + 
(System.currentTimeMillis() - ts));
                }               
        }
}

It seems to me, that regexp implementatiopn shouldn't use recursion but it 
should use finite automata. But both apache implementation and Sun 
one lead to problems (the Sun one seems to have exponential time requirements 
in some similar cases). 
I'm not sure what to do. Is there an regexp implementation, that works OK 
in all cases or should I learn some patterns, that cause troubles and not to 
use them. Or should I create an implementetion, that works fine? :) Or do 
I do some trivial bug I haven't notice?
 -- 
   S pozdravem
       Ondrej Nekola
       [EMAIL PROTECTED]
       http://www.matfyz.cz/ondra

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to