In this narrowed down regex case, each line produces an ERR.

I cannot spot the error. Can you?

Just to be clear, the dollar sign could be one or more other special chars, not just a single dollar sign

my $line1 = 'I:\$AVG'; # Should NOT be okay. my $line2 = 'I:\$AVG\hello.log'; # Should NOT be okay. my $skip = '$AVG'; #------------------------------------------------ if ($line1 =~ m!\b\Q$skip\E\b!i) { print __LINE__." Line 1 Okay!\n"; } else { print __LINE__." Line 1 ERR! $line1 did not match $skip\n"; } if ($line2 =~ m!\b\Q$skip\E\b!i) { print __LINE__." Line 2 Okay!\n"; } else { print __LINE__." Line 2 ERR! $line2 did not match $skip\n"; } __END__ 14 Line 1 ERR! I:\$AVG did not match $AVG 19 Line 2 ERR! I:\$AVG\hello.log did not match $AVG

In reply to regex not matching special char by mnooning

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.