use*_*236 2 regex string variables perl match
我想在Perl中的匹配常规rexpression中包含一个变量,并检查该变量是否在字符串中.
这里的链接指示如何包含变量,但是如果变量不匹配,我将难以测试.当然,我可以像这样否定if条件:
if (!($string =~ m/$Myvar/)) {
# Do some code here
}
Run Code Online (Sandbox Code Playgroud)
但我确信在正则表达式匹配中必须有办法.有任何想法吗?
提前谢谢你的帮助.
使用!~运营商.
if ($string !~ m/$Myvar/) {
# Do some code here
}
Run Code Online (Sandbox Code Playgroud)
或者完全使用index和避免正则表达式引擎.即使$Myvar具有正则表达式引擎专门处理的字符,这也将起作用.
if ( index($string, $Myvar) < 0 ) {
# Do some code here
}
Run Code Online (Sandbox Code Playgroud)