The regex  qr{(?<!foo)\s+bar} will not match
          'foo    bar'
              ^^
              ||
   no match --++-- can match here
at the first position because it's preceded by 'foo', but at the second position it's not preceded by 'foo' but by a whitespace character, so it can match!

Update: If you have Perl version 5.10+, here's one way to simulate a variable-width negative look-behind:

c:\@Work\Perl>perl -wMstrict -le "use 5.010; ;; my $s = 'foo 1 foo 2 foo 3 4 x 567 foo foo 8 foo9'; my @matches = $s =~ m{ (?> foo \s+ \d+ (*SKIP)(*FAIL))? \s+ \d+}xmsg; printf qq{'$_' } for @matches; " ' 4' ' 567'
See Special Backtracking Control Verbs in perlre for  (*SKIP) (*FAIL) and friends.
See also Look Behind issues and Another Look behind for further recent discussion of the variable-width negative look-behind issue. (Update: Variable-width positive look-behind is nicely handled by the  \K operator.)


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


In reply to Re: look behind with multiple whitespace characters by AnomalousMonk
in thread look behind with multiple whitespace characters by RK

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.