View Single Post
 
Old 06-03-2012, 06:46 PM
tinfanide tinfanide is offline Windows 7 64bit Office 2010 32bit
Expert
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default VBScript.RegExp: exclude a particular word

This is not just an Excel VBA question, anyway, I'd post it here for help:

Code:
Dim str6 As String
str6 = "cat and dog"

With CreateObject("VBScript.RegExp")
    
    .Global = True
    .IgnoreCase = True
    .Pattern = "\b[^cat]{3}\b"
    For Each oMatch In .Execute(str6)
        Debug.Print oMatch
    Next oMatch

End With

''' output
''' dog
I want to have any words except "cat" but the above codes also exclude the word "and". How can I do a pattern that excludes a particular word instead of

Code:
.pattern = "[^cat]"
which just shows me
Quote:
(space)
n
d
(space)
d
o
g
in the console.
Reply With Quote