简体   繁体   中英

Detect exact string value of scalar in regex matching

Say I have $foo = "bar.baz"

I want to use the scalar $foo to find strings that contain "bar.baz" (anywhere in the string), but not the regex-evaluted version of $foo.

So the line: if( $other =~ m/$foo/ ) ... isn't working, because $foo is being evaluated such that the '.' is evaluated to any character. How do I stop that?

Pick one:

  1. $foo = quotemeta("bar.baz");
  2. if ($other =~ m/\\Q$foo/)

(Both are actually the same thing, just done at different times.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM