http://qs1969.pair.com?node_id=11140608


in reply to Re: Refer by relative way to regex group (eg. the last one)
in thread Refer by relative way to regex group (eg. the last one)

The \g{-1} syntax is interesting, I don't recall that one. When did it come about? (Of course, it's possible it's been around since Perl 4 and I just missed it :) )

Mike
  • Comment on Re^2: Refer by relative way to regex group (eg. the last one)

Replies are listed 'Best First'.
Re^3: Refer by relative way to regex group (eg. the last one)
by Fletch (Bishop) on Jan 19, 2022 at 14:41 UTC

    Looks like 5.10 according to perl5100delta:

    Relative backreferences A new syntax "\g{N}" or "\gN" where "N" is a decimal integer a +llows a safer form of back-reference notation as well as allowing re +lative backreferences. This should make it easier to generate and emb +ed patterns that contain backreferences. See "Capture buffers" in perlre. (Yves Orton)

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re^3: Refer by relative way to regex group (eg. the last one)
by Corion (Patriarch) on Jan 19, 2022 at 14:40 UTC

    Grepping the perldelta* files for \\g lists perl5100delta, so likely the feature was introduced with Perl 5.10.0.

Re^3: Refer by relative way to regex group (eg. the last one)
by choroba (Cardinal) on Jan 19, 2022 at 14:44 UTC
    Syntax::Construct to the rescue :-)

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
Re^3: Refer by relative way to regex group (eg. the last one)
by LanX (Saint) on Jan 19, 2022 at 14:35 UTC
Re^3: Refer by relative way to regex group (eg. the last one)
by Anonymous Monk on Jan 19, 2022 at 16:00 UTC

    Perl 5.9.5 if you want to be picky.