I think I got it, there is one \s and it is outside of the lookaround, so it gets consumed (advances pos), and backtracking doesn't go back before it, so its checking every other number

Look at the pos, in your version (\s outside (?=)) it jumps 7/15 but with \s inside (?=) it jumps 7/11/15

#! perl -slw use strict; my $data = '105 106 107 108 109 110 111 112 113 1115 1116 1117 1118 1119 1120 1121 1122 1123 12345 12346 12347 12348 12349 12350 12351 12353 '; { my $other = @ARGV ? qr{(?=\s(\d+)\d\s)} : qr{\s(?=(\d+)\d\s)}; open my($DATA),'<',\$data; my $what = ""; while( readline $DATA ) { s{ \s(\d+)\d \K $other }{ warn "WHAT($1)($2)POS(@{[pos()]})\n"; $1 + 1 == $2 ? ";\n" : '! ' }gex; print; } print "\n$what"; } __END__ $ perl junk WHAT(10)(10)POS(7) WHAT(10)(10)POS(15) WHAT(11)(11)POS(23) WHAT(11)(11)POS(31) 105 106! 107 108! 109 110! 111 112! 113 WHAT(111)(111)POS(9) WHAT(111)(111)POS(19) WHAT(112)(112)POS(29) WHAT(112)(112)POS(39) 1115 1116! 1117 1118! 1119 1120! 1121 1122! 1123 WHAT(1234)(1234)POS(11) WHAT(1234)(1234)POS(23) WHAT(1235)(1235)POS(35) 12345 12346! 12347 12348! 12349 12350! 12351 12353 $ perl junk lookaround WHAT(10)(10)POS(7) WHAT(10)(10)POS(11) WHAT(10)(10)POS(15) WHAT(10)(11)POS(19) WHAT(11)(11)POS(23) WHAT(11)(11)POS(27) WHAT(11)(11)POS(31) 105 106! 107! 108! 109; 110! 111! 112! 113 WHAT(111)(111)POS(9) WHAT(111)(111)POS(14) WHAT(111)(111)POS(19) WHAT(111)(112)POS(24) WHAT(112)(112)POS(29) WHAT(112)(112)POS(34) WHAT(112)(112)POS(39) 1115 1116! 1117! 1118! 1119; 1120! 1121! 1122! 1123 WHAT(1234)(1234)POS(11) WHAT(1234)(1234)POS(17) WHAT(1234)(1234)POS(23) WHAT(1234)(1235)POS(29) WHAT(1235)(1235)POS(35) WHAT(1235)(1235)POS(41) 12345 12346! 12347! 12348! 12349; 12350! 12351! 12353

rxrx gave me the idea to pos it


In reply to Re: Why doesn't this regex work? ( lookaround backtracking pos) by Anonymous Monk
in thread Why doesn't this regex work? (Solved!) by BrowserUk

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.