[英]How can I include a variable in a match regular expression in Perl, and check if the variable is NOT in the string?
我想在Perl中的匹配常規rexpression中包含一個變量,並檢查該變量是否在字符串中。
這里的鏈接指示如何包含變量,但是如果變量不匹配,我將難以測試。 當然,我可以像這樣否定if條件:
if (!($string =~ m/$Myvar/)) {
# Do some code here
}
但我確信在正則表達式匹配中必須有辦法。 有任何想法嗎?
提前謝謝你的幫助。
否定結果有什么問題?
“負面匹配”(需要一個負面的先行斷言 )會使你的正則表達式更加復雜:
if ($string =~ m/^(?!.*$Myvar)/s) {
# Do some code here
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.