|
目标是查找不包含另一个单词(cat)的单词,正则表达式为可以完成目标。测试代码:- Private Sub test() '查找不包含另一个单词(cat)的单词
- Dim strTest$, strPattern$, oMatches As Object, oMatch As Object, oReg As Object
- Set oReg = CreateObject("vbscript.regexp")
- strTest = "litcatis ca"
- strPattern = "\b((?!cat)\w)+\b"
- With oReg
- .Global = True
- .MultiLine = True
- .Pattern = strPattern
- Set oMatches = .Execute(strTest)
- MsgBox oMatches.Count
- End With
- For Each oMatch In oMatches
- MsgBox oMatch.Value
- Next
- End Sub
复制代码 问题:为什么不能匹配单词litcatis。按我的理解只要单词开头没有cat就可以匹配到,不理解,望指导。
|
|