开发者

regular expression to negate two conditions

开发者 https://www.devze.com 2023-03-29 19:09 出处:网络
I have two regular expressions: \".*-.*adm.*\" \".*-svc\" Could someone explain how I can go about matching all of the strings which don\'t match/f开发者_开发百科it the two regular expression above

I have two regular expressions:

".*-.*adm.*"
".*-svc"

Could someone explain how I can go about matching all of the strings which don't match/f开发者_开发百科it the two regular expression above?

Ps. Using vbscript


You would or the two expressions and then use Not, like so.

Dim re
Set re = new regexp 

re.Pattern = "(.*-.*adm.*)|(.*-svc)"
re.IgnoreCase = true

if Not re.Test(YOUR_STRING) then
    ' Do whatever
end if


I think negative lookahead is the tool you're looking for:

^(?![^-]*-(?:.*adm|svc)).*
0

精彩评论

暂无评论...
验证码 换一张
取 消