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

Try 148012 :)
  • Comment on Re^2: Regex to match ascending sequence

Replies are listed 'Best First'.
Re^3: Regex to match ascending sequence
by LanX (Saint) on Oct 15, 2015 at 22:45 UTC
    > 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

      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!

Re^3: Regex to match ascending sequence
by ExReg (Priest) on Oct 15, 2015 at 17:35 UTC
    I think that it is to be expected with left-most, longest. It would find the 1, not find a 2 after it and quit, without seeing that there is a 012 later.