Regex again...

Reapz

Well-known member
Joined
Dec 15, 2002
Messages
74
I have the following string...

"some<text><999><STEAM_0:0:000000><text>again some other stuff"

Howcome this...
Code:
system.text.regularexpressions.regex("<.+><STEAM_.+:.+:.+><.+>")
...matches this...

<text><999><STEAM_0:0:000000><text>

...when surely it should only match this...

<999><STEAM_0:0:000000><text>

...?

What am I missing?

I need to match only <999><STEAM_0:0:000000><text> which works when there are no pointy brackets to the left of it but on some occasions such as above there may be and I have no control over how many or where they are placed.

Cheers!
 
"<text><999>" matches the regular expression "<.+>". It starts with a less-than character, has text in the "middle", and ends with a greater-than character. If you want to limit it to just as single tag use "[^<>]".
 
Yea... Of course thats logical.

I tried substituting the first <.+> with [^<>] like you said but it just returned the whole line. Maybe Ive got the wrong end of the stick.

What Ive got is this...

(Currentline = the string from above.)

Code:
Dim reUID As New System.Text.RegularExpressions.Regex("(<.+><STEAM_.+:.+:.+><.*>)")
Dim Parts = reUID.Split(CurrentLine)

What Im trying to get is...

Parts(0) = "some<text>"
Parts(1) = "<999><STEAM_0:0:000000><text>"
Parts(2) = "again some other stuff"

Like I said this works fine if the only <s and >s are the ones in <999><STEAM_0:0:000000><text> which is 99% of the time but not if there are any preceeding that part.

What corrections do I need to make in my regex?
 
Back
Top