I've looked through it with Regexp::Debugger.

Maybe (probably) I'm misunderstanding the question, but in your sample data, the hundred groups in each line seem to be the same. i.e. $1 + 1 will always not equal $2 in this data, for each line.

I think the second point is about the spaces. When the regex matches, it skips a space, so misses out on matching the next number to the first part of the regex.

For example, this inserts a newline before the 200s start:

#!/usr/bin/perl use strict; use warnings; #use Regexp::Debugger; while( <DATA> ) { s[\s(\d+)\d\d\K\s(?=(\d+)\d\d)]{ $1 + 1 == $2 ? "\n" : ' ' }ge; print; } __DATA__ 105 106 107 108 109 110 211 212 213 1115 1116 1117 1118 1119 1120 1121 1122 1123 12345 12346 12347 12348 12349 12350 12351 12353

But when you change the data to:

105 106 107 108 109 210 211 212 213 1115 1116 1117 1118 1119 1120 1121 1122 1123 12345 12346 12347 12348 12349 12350 12351 12353

the first part of the regex doesn't match the 109, because the match fails on the first space.

Apologies if I'm way off!


In reply to Re: Why doesn't this regex work? by mtmcc
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.