开发者

Detect exact string value of scalar in regex matching

开发者 https://www.devze.com 2023-02-18 17:32 出处:网络
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.

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 =~开发者_如何学JAVA 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.)

0

精彩评论

暂无评论...
验证码 换一张
取 消