RegEx mysterious issue

Joined
Dec 14, 2006
Messages
8
Programming Experience
5-10
i'm running a RegEx Match for this pattern:

VB.NET:
"((=?3D=?){21,}[\r\n]{1,2}){3}[\r\n]{1,2}"

The mysterious issue is that it locks the application (seemingly). The cpu spikes at 50% and never drops and the application does not continue. Any help as to why would greatly help.

The match is for the 70 equal signs. However it's parsed within an email so sometimes it comes in as the Hex version of =3D and wraps the line at 70-80 characters (plain text).

I have to split the data into an array based on these line separators so i need them to match.

VB.NET:
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D


TIA

-Jeff Dupont
-CAFM Web Developer


Edit: for some reason there's a space showing in the =3D group when viewing it in the forum, yet not when i submit or edit it.
 
Last edited by a moderator:
VB.NET:
        'Gathers the data
        _data = Data
        'Crop off the unneeded html version of the email
        a = Regex.Split(_data, "Content-Type: text/html;")
        _data = a(0)
        'Replace all random hex values
        _data = Regex.Replace(_data, "=20", "")
        _data = Regex.Replace(_data, "=3D3D", "=3D")
        'create the pattern to split the sections
        If Regex.Match(_data, "(={70,})").Success Then
            pattern = "(={70,})"
        ElseIf Regex.Match(_data, "((=?3D=?)+[\r\n]{1,2}){2,}").Success Then
            pattern = "((=?3D=?)+[\r\n]{1,2}){2,}"
        ElseIf Regex.Match(_data, "((=?3D=?){21,}[\r\n]{1,2}){3}[\r\n]{1,2}").Success Then
            pattern = "((=?3D=?){21,}[\r\n]{1,2}){3}[\r\n]{1,2}"
        End If
        If pattern IsNot "" Then
            a = Regex.Split(_data, pattern)
        End If
 
Last edited by a moderator:
Here is a matching expression that doesn't loop indefinitely:
VB.NET:
[SIZE=2][COLOR=#0000ff]
Dim[/COLOR][/SIZE][SIZE=2] expression [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#800000]"((=3D){21,}[\r\n]{1,2}){3}[\r\n]{1,2}"
[/COLOR][/SIZE]
 
ok, just for understanding... i'm fairly new to the more sophisticated regex expressions... but what would've caused it to loop indefinitely? i thought that the expression just ran through the data once looking for a match and that was it.

-Jeff
 
No, regex isn't linear, it searches back and forth as much as possible given the expression, it won't stop even if a match is found if there are more possibilities to search for within the scope of that expression. I can imagine your optionals (?) with repetetive query (backtracking 21+ times 3) and repetetive input text gave the engine quite a lot to chew on.

Have you read this site:? http://www.regular-expressions.info
 
Back
Top