我正在尝试编写正则表达式,因为句子中没有单词Regular
。
句:
c= "Regular Expression should not be present".
我的代码:
RegularExpressionObject.IgnoreCase = True
RegularExpressionObject.Global = True
RegularExpressionObject.Pattern = "(Regular){0}" ' this is to make sure the word "Regular" is not 'available
Set Matches3 = RegularExpressionObject.Execute(c)
If (Matches3.Count = 0) Then
MsgBox ("Regular Expression do not match")
Else
MsgBox ("they match")
End If
我无法成功,任何人都可以根据我的需要帮助我纠正模式。
答案 0 :(得分:1)
如果您希望匹配在Regular
字符上失败(即Regularity
也会失败),那么您的正则表达式不应该{0}
。你实际上可以简单地使用:
c = "Regular Expression should not be present"
If (InStr(c,"Regular") > 0) Then
MsgBox ("'Regular' is in c")
Else
MsgBox ("'Regular' is not in c")
End If
也就是说,你真的不需要正则表达式。
好吧,如果你想要一个正则表达式解决方案,我想你可以尝试这样的事情:
RegularExpressionObject.IgnoreCase = True
RegularExpressionObject.Global = True
RegularExpressionObject.Pattern = "Regular"
Set Matches3 = RegularExpressionObject.Execute(c)
If (Matches3.Count = 0) Then
MsgBox ("'Regular' is not in c")
Else
MsgBox ("'Regular' is in c")
End If
我认为这更接近你的尝试。如果Regular
匹配,则说明它出现在字符串中。