in reply to Advanced techniques with regex quantifiers

Note that we need to manually coerce the count to a plain integer, because .{04} is invalid - it has to be .{4}.

I don't see this in either 5.8.9 or 5.14.4. I thought the '010' might look like octal, but apparently not (actually, this surprises me a bit).

c:\@Work\Perl>perl -wMstrict -MData::Dump -le "my $s = '004abcdefgh009ABCDEFGHIJKLM010nopqrstuvwxyz'; ;; my @captures = $s =~ m{ (\d\d\d) ((??{ qr{.{$^N}}xms })) }xmsg; dd @captures; " ("004", "abcd", "009", "ABCDEFGHI", "010", "nopqrstuvw")
(The A.1 example code also doesn't seem to need coercion of  $1 to an integer.)

So while it's reasonable to think it might be true, it apparently isn't. What led you to think it was?


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

Replies are listed 'Best First'.
Re^2: Advanced techniques with regex quantifiers
by smls (Friar) on Jul 19, 2015 at 21:52 UTC

    For me your code fails with:

    Invalid quantifier in {,} in regex; marked by <-- HERE in m/.{ <-- HER +E 004}/ at -e line 1.

    Similarly for my own example code if I leave out the integer coercion.

    This is with Perl 5.22.
    Is this a regression then?

    Update: I annotated the quoted sentence in the article with a link to this discussion.

      For me your code fails […] with Perl 5.22. Is this a regression then?

      So it would seem. Apparently I need to take a look at the deltas.


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

        Hello AnomalousMonk,

        Your code works fine for me in Perl 5.20.2, but breaks in Perl 5.22.0 with the runtime error reported by smls. perl5220delta has the following in its New Diagnostics section:

        (Note: the (F) here indicates a fatal but trappable error.)

        So it seems that leading zeroes in a quantifier were always meant to be considered an error, but were previously overlooked?

        Hope that helps,

        Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,