Note that in the comments of the code examples in the Positive and Negative Look-behind sections, e.g.
    '(?<=this\ )that' # match 'that' when followed by 'this '
    '(?<!this\ )that' # match 'that' when NOT followed by 'this '
the word "followed" should be "preceded" in both cases, i.e.
    '(?<=this\ )that' # match 'that' when preceded by 'this '
    '(?<!this\ )that' # match 'that' when NOT preceded by 'this '
respectively.

Both the PRECEDING_PATTERN and the FOLLOWING_PATTERN are matched as the 'look-around' patterns, but neither are captured to a variable, only what is matched as part of your (PATTERN_OF_INTEREST) capture group ...

As an interesting (I hope) side note, a capture group embedded within a positive lookaround assertion will capture something:

c:\@Work\Perl\monks>perl -wMstrict -le "my $s = 'foobar'; ;; print qq{positive look-behind capture: '$1'} if $s =~ m{ (?<= (foo)) + bar }xms; print qq{positive look-ahead capture: '$1'} if $s =~ m{ foo (? += (bar)) }xms; " positive look-behind capture: 'foo' positive look-ahead capture: 'bar'

An embedded positive look-ahead capture is a way to capture and extract certain overlapping matches:

c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "my $s = 'abcd efgh'; ;; my @caps = $s =~ m{ \w+ }xmsg; dd 'non-overlapping captures: ', \@caps; ;; @caps = $s =~ m{ (?= (\w+)) }xmsg; dd 'overlapping captures: ', \@caps; " ("non-overlapping captures: ", ["abcd", "efgh"]) ( "overlapping captures: ", ["abcd", "bcd", "cd", "d", "efgh", "fgh", "gh", "h"], )

Update: Slight, essentially trivial wording and emphasis changes.


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


In reply to Re^2: Remove all lines, except those starting with pattern by AnomalousMonk
in thread Remove all lines, except those starting with pattern by bbs2web

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.