开发者

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜