'code to accompany Mike McMillan's article on Regular Expressions Dim regex, match, matches, ptrn, strng ptrn = "as." strng = "as1 As2 aS3 AS4" Set regex = New RegExp regex.Pattern = ptrn regex.IgnoreCase = True regex.Global = True Set matches = regex.Execute(strng) For Each match in matches retstr = retstr & "Match found at position " retstr = retstr & Match.FirstIndex & ". Match value is ‘" retstr = retstr & Match.Value & "’." & vbCrLf Next MsgBox retstr Dim regex, ptrn, repstr, str1 ptrn = "men" repstr = "people" str1 = "Now is the time for all good men to come" str1 = str1 & " to the aid of their party" set regex = New RegExp regex.Pattern = ptrn str1 = regex.Replace(str1, repstr) MsgBox str1 Dim regex, ptrn, repstr, str1 ptrn = "we" repstr = "they" str1 = "what we know we know we know" set regex = New RegExp regex.Pattern = ptrn regex.Global = True str1 = regex.Replace(str1, repstr) MsgBox str1 Dim regex, ptrn, repstr, str1 ptrn = "we" repstr = "they" str1 = "what we know we know we know" str1 = str1 & " to the aid of their party" set regex = New RegExp regex.Pattern = ptrn If regex.Test(str1) Then regex.Global = True str1 = regex.Replace(str1, repstr) MsgBox str1 End If dim regex, ptrn, strng, wc, matches set regex = New RegExp ptrn = "\s" strng = "This string is six words long" regex.Pattern = ptrn regex.Global = True set matches = regex.Execute(strng) wc = matches.Count MsgBox "Found " & wc+1 & " word matches" dim regex, ptrn, strng, wc, matches set regex = New RegExp ptrn = "(sh)" strng = "she shucks sea shells by the sea shore" regex.Pattern = ptrn regex.Global = True set matches = regex.Execute(strng) retstr = matches.item(2) MsgBox retstr