in reply to Match multiple words in a string ?
This gives you those strings that did match. But it breaks once $str_to_find contains data that is parsed as regexp metacharacter, since these modify the behavior of the match -- you can get both false positives and miss on true matches.
So the solution is to quotemeta $str_to_match first, and match against that:
$quoted_str_to_match = quotemeta $str_to_match; @matches = grep /$quoted_str_to_match/, @Output;
You can read up on quotemeta and \Q in perlre.
Update: D'oh! TMTOWTDI, but friedo's way is much simpler in this case :-)
Still, quotemeta/\Q are good to know about.
|
|---|