in reply to help needed to solve in regex

You're using a string where a regular expression is expected.

my $find_re = qr/1\.2\.3/i; ... grep /$find_re/, ... ...

or

my $find_str = '1.2.3'; my $find_re = quotemeta($find_str); ... grep /$find_re/i, ... ...

or

my $find_str = '1.2.3'; ... grep /\Q$find_str\E/i, ... ...

Replies are listed 'Best First'.
Re^2: help needed to solve in regex
by diotalevi (Canon) on Jan 10, 2007 at 05:59 UTC

    You forgot the surround the pattern with \b markers.

    /\b\Q$find\E\b/

    ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

      oh, I didn't notice that matched the third line. Unforunately, I don't agree with your solution. That is to say I don't think we can provide a solution with the information he provided us. For example, all of the following match his criteria, yet all are different:
      • /\b\Q$find\E\b/
      • /(?<!\S)\Q$find\E/(?!\S)
      • /\Q$find\E/(?!\.)
      • /\Q$find\E$/
      • /\Q$find\E$/m
      • /\Q$find\E\z/
      • ...

      The op should have a look at perlre. (Or should I say "another look" since he should already have looked there when he started having problems with his regexp...)