Regular Expressions in VBScript
Finding string patterns within a text, or Regular Expressions as the are called, can be easily accomplished in VBScript. Below is a sample code that illustrates how to find the pattern “-L” from a search string.
First we must declare our search string and create our Regular Expression Object.
strSearchString = “TPA-FWR-L001″
Set objRegExp = New RegExp
We then need to tell the object how to behave and what to look for. For example in our case we want to search for the pattern “-L” from within our search string. We have chosen to ignore case, so it will return a positive result for both upper and lower case. Lastly, we only want to return a positive result at the first occurance. By changing the global property to True it will return all instances.
With objRegExp
.Pattern = “-L”
.IgnoreCase = True
.Global = False
End With
We then want to execute our search and return the result into ExpMatch
Set ExpMatch = objRegExp.Execute(strSearchString)
And lastly, we verify if a match is found and return the result for each match.
If ExpMatch.Count > 0 Then
For Each Matched in ExpMatch
‘Code to execute for each match goes here
MsgBox “Expression ” & objRegExp.Pattern & ” was found”
Next
End If
Filed under: Scripts

The article is ver good. Write please more
Great post! I’ll subscribe right now wth my feedreader software!
The article is usefull for me. I’ll be coming back to your blog.
Hello, can you please post some more information on this topic? I would like to read more.