Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

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

by LanX (Sage)
on Jan 19, 2022 at 01:22 UTC ( #11140601=note: print w/replies, xml ) Need Help??


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

You may wanna try the two possibilities listed in perlretut and perlvar

You got those links already last time you asked.

Additionally has perlre even a demo similar to your code.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

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

Replies are listed 'Best First'.
Re^2: Refer by relative way to regex group (eg. the last one)
by RMGir (Prior) on Jan 19, 2022 at 14:28 UTC
    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

      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.

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

      Syntax::Construct to the rescue :-)

      map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

      Perl 5.9.5 if you want to be picky.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11140601]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2022-05-27 06:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (94 votes). Check out past polls.

    Notices?