本文介绍了用于“没有特定单词"的 VBscript 正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写正则表达式,因为句子中没有Regular这个词.

I am trying to write regular expression for not having the word Regular in the sentence.

句子:

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

我无法成功,任何人都可以根据我的需要通过更正模式来帮助我.

I am not able to succeed, could anybody please help me by correcting pattern as per my need.

推荐答案

如果您希望匹配在字符 Regular 上失败(即它应该失败 Regularity 作为好吧),那么您的正则表达式不应该有 {0}.你实际上可以简单地使用:

If you want the match to fail on the characters Regular (i.e. it should fail for Regularity as well), then your regex shouldn't have {0}. You can actually simply use:

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

也就是说,您实际上并不需要正则表达式.

That is, you don't really need a regex for that.

好吧,如果你想要一个正则表达式解决方案,我想你可以尝试这样的事情:

Well, if you want a regex solution, I guess you could try something like this:

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 匹配,则说它存在于字符串中.

Which I think is closer to what you were attempting. If Regular matches, then say that it's present in the string.

这篇关于用于“没有特定单词"的 VBscript 正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 18:53