有没有这样的正则表达式:
" /您好我的名字是[任何不是"约翰"],我喜欢披萨/"
因此,当我与此正则表达式匹配时,只要名称所在的位置不是" john"就会返回true。
"Heloo my name is abcd, and I like pizza" --> false
"Hello my name is asdf, and I like pizza" --> true
"Hello my name is john, and I like pizza" --> false
我的正则表达式应该以最佳方式执行此操作?
答案 0 :(得分:3)
Hello\smy\sname\sis\s(?:(?!\bjohn\b).)*?\sand\sI\slike\spizza
试试这个。看看演示。
答案 1 :(得分:3)
试试这个。
/Hello my name is (?!john)[^,]+, and I like pizza/
答案 2 :(得分:0)
通过PCRE动词(*SKIP)(*F)
Hello my name is john, and I like pizza(*SKIP)(*F)|Hello my name is [^,]+, and I like pizza
|<----String you don't want----------->|<-VERB--->|<------String you want----------------->