I am using Apache regexp as library to validate regex. I want to know how to track if some regex is causing catastrophic backtracking. What I want to know is, is there some trick to catch which regex and the string value that causing catastrophic backtracking? I tried a little modify in class RE.java, but not as expected.
This my modification:
public RE(String pattern) throws RESyntaxException
{
this(pattern, MATCH_NORMAL);
paramString = pattern;
}
public RE(String pattern, int matchFlags) throws RESyntaxException
{
this(new RECompiler().compile(pattern), matchFlags);
paramString = pattern;
}
int callcounterMN = 0;
protected int matchNodes(int firstNode, int lastNode, int idxStart)
{
callcounterMN++;
if (callcounterMN == 100) {
try {
String pc1 = new Exception().getStackTrace()[5].getClassName();
if (pc1.indexOf("UpdateWebForm") > 1)
System.out.println("regex loop reach "+callcounterMN+" with regex : "+paramString+" "+this.search.substring(0));
} catch (Exception e) {}
}