in reply to Re^2: Regex to match ascending sequence
in thread Regex to match ascending sequence

> Try 148012 :)

This should do

my $regex = qr/ \d (??{ substr($&, -1) + 1 }) + /x; "148012" =~ $regex; print ">$&<" __END__ >012<

The minimal length of the sequence can be set by {x,} instead of the + quantifier. ¹

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

¹) with x = min-1

Replies are listed 'Best First'.
Re^4: Regex to match ascending sequence
by ExReg (Priest) on Oct 16, 2015 at 14:41 UTC
    Beautiful. I substituted the {x,} in for the + as you suggested and it worked on longer sequences. These will go a long way to help me understand how to construct dynamic regexes.
      > These will go a long way to help me understand how to construct dynamic regexes.

      Well they are flagged experimental and there are only few situations where you can't find an easier and better readable alternative.

      Especially this use case!

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!