Page 1 of 1

How to optimize this REGEX

Posted: Tue Dec 16, 2008 1:38 am
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

Re: How to optimize this REGEX

Posted: Tue Dec 16, 2008 2:14 am
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