How to optimize this REGEX

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
Qasimzee
Forum Newbie
Posts: 1
Joined: Tue Dec 16, 2008 1:31 am

How to optimize this REGEX

Post by Qasimzee »

Hi All,

I am using this regex in a program in a C# program but it is taking so much time when executed on larger data.

"<((P)|(DIV))[^>]*>\\s*(<A[^>]*>)*\\s*(<FONT[^>]*>)?\\s*(<BR>)?\\s*(<B>)?\\s*(<FONT[^>]*>)?\\s*(\\-)?\\s*((\\d\\d?\\d?)|(i+))\\s*(\\-)?\\s*(</font>)?\\s*(</p>)?\\s*(</div>)?\\s*(<P[^>]*>)?\\s*(</P>)?\\s*((<[^>]*>)|(\\s))*<hr[^>]*>"

Can any one please help me optimize this

Thanx in advance
User avatar
prometheuzz
Forum Regular
Posts: 779
Joined: Fri Apr 04, 2008 5:51 am

Re: How to optimize this REGEX

Post by prometheuzz »

Where possibly use: non-capturing parentheses [1] and possessive quantifiers [2] or atomic grouping [3].

[1] http://www.regular-expressions.info/brackets.html
[2] http://www.regular-expressions.info/possessive.html
[3] http://www.regular-expressions.info/atomic.html
Post Reply