Sorry, it seems that my attachment didn't make it through in my prior email.
And here is how I ran it: java TestRegex ^[A-Za-z0-9#_!'\(\)\-]+([A-Za-z0-9#_!'\(\)\.\-]+)[EMAIL PROTECTED]'\(\)\-]+[\.]+([AZa-z0-9#_!'\(\)\.\-]+)+$ [EMAIL PROTECTED] -----Original Message----- From: Kumar, Vasanth Sent: Tuesday, February 25, 2003 4:56 PM To: [EMAIL PROTECTED] Subject: Infinite Loop or Just taking too long ? Hi, We use ORO in our application for to provide regular expression capability. One of our users had created an email validation expression as follows: ^[A-Za-z0-9#_!'\(\)\-]+([A-Za-z0-9#_!'\(\)\.\-]+)[EMAIL PROTECTED]'\(\)\-]+[\.]+([AZa-z0-9#_!'\(\)\.\-]+)+$ As you can see, this is inefficient and can be simplified to (at least) the following: ^[A-Za-z0-9#_!'\(\)\-]+[A-Za-z0-9#_!'\(\)[EMAIL PROTECTED]'\(\)\-]+[\.]+[AZa-z0-9#_!'\(\)\.\-]+$ However, the original expression seems to hang ORO when given a long, invalid, email. (Though I must admit I don't know whether it is hanging or just taking a really long time.) An example of an email that seems to slow it down/hang is: [EMAIL PROTECTED] Note that valid emails are evaluated successfully (i.e. [EMAIL PROTECTED] doesn't hang ORO). I am enclosing my test case as well. This seems to be an issue in the latest version - 2.0.7.
import java.util.*; import org.apache.oro.text.regex.PatternMatcher; import org.apache.oro.text.regex.PatternCompiler; import org.apache.oro.text.regex.Pattern; import org.apache.oro.text.regex.PatternMatcherInput; import org.apache.oro.text.regex.MatchResult; import org.apache.oro.text.regex.Util; import org.apache.oro.text.regex.Perl5Compiler; import org.apache.oro.text.regex.StringSubstitution; import org.apache.oro.text.regex.Perl5Matcher; import org.apache.oro.text.regex.MalformedPatternException; public class TestRegex { public static void main(String[] args) { try { PatternMatcher oroMatcher; PatternCompiler oroCompiler; Pattern oroPattern; PatternMatcherInput oroInput; String sExpr = args[0]; String sData = args[1]; oroCompiler = new Perl5Compiler(); oroMatcher = new Perl5Matcher(); oroPattern = oroCompiler.compile(sExpr, Perl5Compiler.CASE_INSENSITIVE_MASK); MatchResult oroResult; oroInput = new PatternMatcherInput(sData); if (oroMatcher.contains(oroInput, oroPattern)) { System.out.println("Match"); oroResult = oroMatcher.getMatch(); int totalGroups = oroResult.groups(); for(int groupNum = 0; groupNum < totalGroups; groupNum++) { System.out.println("match: " + oroResult.group(groupNum)); } } else { System.out.println("No match"); } } catch (Exception e) { e.printStackTrace(); System.out.println(e); } } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]