[RESOLVED] help with Regular Expressions!
Hey guys,
Quick query...
I'm trying to scan a long string and return any values that occur between the tags <FileName> and </FileName>
I've got a bit of code here to use regular expressions to return the position of the occurunces of both substrings..
Just wanted to find out if there is any way to scan for both substrings within one loop (as im currently doing 2, one for the first substring and one for the 2nd) so I can use something along these lines:
Code:
ringlist = Mid(XMLRESP, (startloc + 1), (endloc - 1))
MsgBox(ringlist)
to msg box the value between the substrings...
either that or another approach to return the value between the 2 substrings (it can be of variable length)
Code:
Dim patternstart As String = "<FileName>"
Dim patternend As String = "</FileName>"
Dim matchesstart As MatchCollection = Regex.Matches(XMLRESP, patternstart)
Dim matchesend As MatchCollection = Regex.Matches(XMLRESP, patternend)
Dim startloc As String
Dim endloc As String
startloc = ""
endloc = ""
'The matches collection now contains Indexes and other information about all of the matches
For Each m As Match In matchesstart
startloc = startloc + m.Index.ToString
Next
For Each n As Match In matchesend
endloc = endloc + n.Index.ToString
Next
Re: help with Regular Expressions!
vb Code:
Dim rx As New Regex("(?<=<FileName>).+?(?=</FileName>)")
For Each m As Match In rx.Matches(yourString)
MsgBox(m.Value)
Next
Re: help with Regular Expressions!
You truly are the king.
Thanks dude,
you've saved me a hell of a lot of hassle!
dan
Re: [RESOLVED] help with Regular Expressions!
click the scales icon to the left of this message
<--------------------------------------------