VBScript Basics, Part 71 | RegExp (Execute)

| VBScript (.vbs) Tutorial
Learn how to create a match collection object out of your regular expression string with the Execute method, and then how to use Count, Item, FirstIndex, Length, and Value with that object.

| Code Example
Set reg = new RegExp
reg.Pattern = “your_pattern”
reg.Global = True

reg.Execute(“your string”).Count ‘number of matches
reg.Execute(“your string”).Item(#) ‘get a specific match

reg.Execute(“your string”).Item(#).FirstIndex ‘ get location of match
reg.Execute(“your string”).Item(#).Length ‘ get length of match
reg.Execute(“your string”).Item(#).Value ‘ get value of match

‘ use a loop
For Each match In reg.Execute(“your string”)
msgbox _
“Value: ” & match.Value & vbLf & _
“First Index: ” & match.FirstIndex & vbLf & _
“Length: ” & match.Length

| Paypal Contribution