I've avoided RegExp for a long time, since it mostly looks like some sort of mysterious voodoo magic to me, but I'm finally taking the plunge and trying to get some stuff working with a couple RegExp routines because they just make the most sense.
I got my first process to work, and now I'm working on a second one. For some reason, the second one is returning results that don't make a whole lot of sense to me, so I thought I'd see if someone could explain it, and possibly also help me get it to do what I'm looking to do.
Here's my code:
Code: Select all
<%
str = "delim item1 delim some text delim item2 delim some other text delim item3 delim yet more text delim"
'setup regexp
Set objRegExp = New RegExp
objRegExp.Pattern = "delim.*delim"
'objRegExp.Pattern = "(delim)(.*)(delim)"
objRegExp.Global = True
Set Matches = objRegExp.Execute(str)
For Each Match in Matches
Response.Write "<br><br>Text: "" & Match.Value & "" found at position " & Match.FirstIndex & "<BR>"
Next
%>
Code: Select all
Text: "delim item1 delim some text delim item2 delim some other text delim item3 delim yet more text delim" found at position 0
What I expected, after realizing that I'd made an error in my code, was all the combinations of delim whatever delim to show up in the Matches collection, but I only get the one. Why is that?
Part 2 for bonus points:
As you might have guessed from the original string, I'm looking for a way to grab the text that corresponds to an item, and delims are as delimiters. So what I'd like to be able to do is look for something like:
delim item delim .* delim
So if I was looking for item2, I would set the pattern to:
delim item2 delim .* delim
And get it to return only:
delim item2 some other text delim
Which would allow me to parse out the the text by using a Mid method combined with some Len statements.
Any ideas or thoughts? I'm sure this must be something like RegExp101, but I've never taken that class.
