我想有一个正则表达式模式匹配的行:
1,本行必须包含字符串的末尾不能“单词“S200”
2.消费满”,‘爵士’,‘JSON’,‘CSS’正则表达式来排除模式,但包括图案
这里是一个怪物我,不工作
(?=^.*$(?<!sping)(?<!js)(?<!css)(?<!json))(?=s200)
我是新来的正则表达式,任何帮助,将aapreciated !
我想有一个正则表达式模式匹配的行:
1,本行必须包含字符串的末尾不能“单词“S200”
2.消费满”,‘爵士’,‘JSON’,‘CSS’正则表达式来排除模式,但包括图案
这里是一个怪物我,不工作
(?=^.*$(?<!sping)(?<!js)(?<!css)(?<!json))(?=s200)
我是新来的正则表达式,任何帮助,将aapreciated !
对于初学者来说,你的正则表达式不匹配任何东西,因为你只有你的正则表达式。
?= # look ahead for match
?<! # negative look behind
换句话说,你不匹配任何东西,你的正则表达式,你正在寻找一个字符串position
。
解释:
(?= # pos. lookahead
^.*$ # read anything
# and AFTER reading everything, check
(?<!sping) # if you have NOT read sping
(?<!js) # if you have NOT read js
(?<!css) # if you have NOT read css
(?<!json) # if you have NOT read json
)
(?=s200) # from this position, check if there's "s200" ahead.
结论:你的正则表达式永远不会满足您的要求。
你可以只用一个正则表达式解决这个问题,例如使用:
(.*)s200(.*)$(?<!css|js|json|sping)
它说
.* # read anything
s200 # read s200
.* # read anything
$ # match the end of the string
(?<!css|js|json|sping) # negative lookbehind:
# if you have read css,js,json or sping, fail
你可以在两个步骤做到这一点很简单:
/s200/
/css|js(on)?|sping$/
您已经标记这是perl
,所以这里是一个perl
解决方案:
$_ = $stringToTest;
if (/s200/) {
# We now know that the string contains "s200"
if (/sping|json|js|css$/) {
# We now know it end with one of sping,json,js or css
}
}
您应该解释为什么OP的工作不起作用,因为这是个问题。 –
这_must_是正则表达式? –
'(?s)^(?!sping $)(?!js $)(?! css $)(?! json $)(?= s200)' –