On Wed, Aug 5, 2009 at 1:37 PM, Christopher
Bodnar<[email protected]> wrote:
> myRegExp.Pattern = "[^\x22]*"
That says, "Give me everything that's not a quote", not "give me
everything quoted". So, if your target string is:
FOO "SERVER1" BAR "SERVER2" BAZ
You will get matches of "FOO ", "SERVER1", " BAR ", "SERVER2", and "
BAZ", complete with the embedded spaces. That is probabbly not what
you want.
Of course, in my testing right now, I'm discovering VBScript does
not appear to support grouping the way I expected. I figured Matches
would be the groups, i.e., the backreferences, but no, it's giving the
whole matched substring, complete with the leading/trailing quotes.
So here's further corrections to my idea. With tested code this time. :-)
target = "target ""SERVER1"" BAR ""SERVER2"" BAZ"
Set re = New RegExp
re.Global = True
'
WScript.Echo "---wrong---"
re.Pattern = "[^\x22]*"
Set matches = re.Execute(target)
For Each match In matches
WScript.Echo "<" & match.Value & ">"
Next
'
WScript.Echo "---correct---"
re.Pattern = "\x22([^\x22]+)\x22"
Set matches = re.Execute(target)
For Each match In matches
For i = 0 to (match.SubMatches.Count - 1)
WScript.Echo "<" & match.SubMatches(i) & ">"
Next
Next
-- Ben
~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/> ~