07-15-2012, 03:02 PM
Try this,
Regards,
Ravi
Code:
strng="ABC is good at testing.ABC is working on PC.ABC is playing games."
Function RegExpTest(patrn, strng)
Dim regEx, Match, Matches ' Create variable.
Set regEx = New RegExp ' Create a regular expression.
regEx.Pattern = patrn ' Set pattern.
regEx.IgnoreCase = True ' Set case insensitivity.
regEx.Global = True ' Set global applicability.
Set Matches = regEx.Execute(strng) ' Execute search.
For Each Match in Matches ' Iterate Matches collection.
RetStr = RetStr & "Match found at position "
RetStr = RetStr & Match.FirstIndex & ". Match Value is '"
RetStr = RetStr & Match.Value & "'." & vbCRLF
Next
RegExpTest = RetStr
msgbox "No of occorences: "&Matches.count
End Function
MsgBox(RegExpTest("abc.",strng))
Regards,
Ravi