0

I have a paragraph on which i am trying to apply a regular expression. Unfortunately its entering into an infinite loop. Could you please let me know what is wrong with this regex.

Regex,

(([A-Z]\w*[\s\.\u0026]*){1,}\s(\d{4})|(\d{4})\s([A-Z]\w*[\s\.\u0026]*){1,})\s(\(\d+\))\s(\d+)

Paragraph,

WHEREAS Dr. L. S. Meena, Scientist C Gr. IV(2) has been convicted on criminal charge under section 815.04(4)(A) Offence against Intellectual Property during his stay in USA under BOYSCAT Fellowship and has been awarded a sentence to serve 24 day(s) in the Orange County Jail with credit for 24 day(s) time served w.e.f. 22nd March, 2005 by the CIRCUIT COURT OF THE NINTH JUDICIAL CIRCUIT, IN AND FOR ORANGE COUNTY, FLORIDA, USA.

Also can you tell me is there any tool that could tell me if there are any loopholes in the regex written?

Thanks, Harsha

5
  • 6
    What is this regex supposed to be doing? Commented Aug 2, 2012 at 9:19
  • Problems may be arising from regex like {1,} for once or more times, you would be better using x+, x+? or x++. See here for information about quantifiers in java. Commented Aug 2, 2012 at 9:24
  • @SeanKenny That can't help as those are nothing but synonims. Commented Aug 2, 2012 at 9:38
  • @MarkoTopolnik Agreed but they do the same thing in subtly different ways. Commented Aug 2, 2012 at 9:46
  • rubular.com/r/Tet97UhR4T Rubular suspects this regex will take forever to parse. Regexes of this sort make Rubular sad. Commented Aug 2, 2012 at 12:07

1 Answer 1

1

That looks like a 'pathological' regex, i.e. it suffers from catastrophic backtracking because of the repeated repeats, such as ([A-Z]\w*[\s\.\u0026]*){1,}.

Catastrophic backtracking is explained here: http://www.regular-expressions.info/catastrophic.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.