Regex Perl中的正则表达式用于排除模式但包含模式
我想要一个正则表达式模式来匹配一行:Regex Perl中的正则表达式用于排除模式但包含模式,regex,perl,Regex,Perl,我想要一个正则表达式模式来匹配一行: 1.此行必须包含单词“s200” 2.字符串的结尾不能是“sping”、“js”、“json”、“css” 这是我得到的一个怪物,它不工作 (?=^.*$(?) 我是新来的正则表达式,任何帮助都是宝贵的!对于初学者,您的正则表达式不匹配任何东西,因为您的正则表达式中只有lookarounds ?= # look ahead for match ?<! # negative look behind 结论:您的正则表
1.此行必须包含单词“s200”
2.字符串的结尾不能是“sping”、“js”、“json”、“css” 这是我得到的一个怪物,它不工作
(?=^.*$(?)
我是新来的正则表达式,任何帮助都是宝贵的!对于初学者,您的正则表达式不匹配任何东西,因为您的正则表达式中只有lookarounds
?= # look ahead for match
?<! # negative look behind
结论:您的正则表达式永远不会符合您的要求
您只需使用一个正则表达式即可解决此问题,例如:
(.*)s200(.*)$(?<!css|js|json|sping)
(.*)s200(.*)(?
上面说
.* # 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#读s200
阅读任何东西
$#匹配字符串的结尾
(?
您可以通过两个步骤完成此简单操作:
- 首先检查字符串是否包含带有
/s200/
- 检查字符串是否以sping、js、json或json结尾,并使用
/css|js(on)?|sping$/
对于初学者,您的正则表达式不匹配任何东西,因为您的正则表达式中只有lookarounds
?= # look ahead for match
?<! # negative look behind
结论:您的正则表达式永远不会符合您的要求
您只需使用一个正则表达式即可解决此问题,例如:
(.*)s200(.*)$(?<!css|js|json|sping)
(.*)s200(.*)(?
上面说
.* # 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#读s200
阅读任何东西
$#匹配字符串的结尾
(?
您可以通过两个步骤完成此简单操作:
- 首先检查字符串是否包含带有
/s200/
- 检查字符串是否以sping、js、json或json结尾,并使用
/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
}
}
您已将其标记为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
}
}
它必须是regex?(?s^(?!sping$)(?!js$)(?!css$)(?!json$)(?=s200)
它必须是regex?(?s^(?!sping$)(?!js$)(?!css$)(?!json$)(?=s200)
你应该解释为什么OP的努力不起作用,因为这是个问题。你应该解释为什么OP的努力不起作用,因为这是个问题。