If you're looking for in-line control of case insensitivity, use  (?i) to turn it on;  (?-i) turns it off. See  (?imsx-imsx) in Extended Patterns in perlre.

c:\@Work\Perl\monks>perl -wMstrict -le "my @needles = ('1-2 Steps', '5-7 Steps', '8-10 Steps', 'cAtCh', '*+ +??er',); my @haystacks = ( 'move 1-2 steps', 'move 8-10 steps to hoist', 'catch the ball', 'du +mb *+??ER', ); ;; for my $needle (@needles) { my $found; for my $haystack (@haystacks) { if ($haystack =~ /(?i)\Q$needle\E/) { print qq{Found [$needle] in [$haystack]}; ++$found; } } ;; if (!$found) { print qq{Could not find [$needle] anywhere!}; } } " Found [1-2 Steps] in [move 1-2 steps] Could not find [5-7 Steps] anywhere! Found [8-10 Steps] in [move 8-10 steps to hoist] Found [cAtCh] in [catch the ball] Found [*+??er] in [dumb *+??ER]


Give a man a fish:  <%-{-{-{-<


In reply to Re: regex for case insensitive by AnomalousMonk
in thread regex for case insensitive by rohan_532

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.