I would like to include a variable in a match regular rexpression, in Perl, and check if the variable is NOT in the string.
The link here instructs how to include the variable, but I’m having difficulty testing if the variable is NOT matched. Sure, I could just negate an if conditional like this:
if (!($string =~ m/$Myvar/)) {
# Do some code here
}
But I’m sure there must be a way to do within the regular expression match.
Any ideas?
Thank you for your help, in advance.
Use the
!~operator.Or use
indexand avoid the regular expression engine altogether. This will work even if$Myvarhas characters that the regular expression engine treats specially.