in reply to \g{-2} for inside (?{ ... })

m{ (?(DEFINE) (?<x> ( . ) ( . ) (?{ '...' }) ) (?<y> (?<y1> . ) (?<y2> . ) (?{ print("($+{y1},$+{y2})") }) ) (?<z> ( . ) ( . ) (?{ '...' }) ) ) (?&y)+ }x;

Replies are listed 'Best First'.
Re^2: \g{-2} for inside (?{ ... })
by ikegami (Patriarch) on Nov 06, 2008 at 20:49 UTC
    Thanks. That's the only documented approach I've found that doesn't rely on counting captures, but it makes for mighty long patterns and mighty long names.
      and mighty long names

      Can't you just use 'x' and 'y' over and over? Doesn't %+ give you the most-recently matched instance matching the given name?

      - tye        

        Indeed! I misunderstood the documentation.

        use 5.010; # re features use strict; use warnings; for ('abcdef') { m{ (?(DEFINE) (?<x> (?<i1> . ) (?<i2> . ) (?{ '...' }) ) (?<y> (?<i1> . ) (?<i2> . ) (?{ print("($+{i1},$+{i2})") }) ) (?<z> (?<i1> . ) (?<i2> . ) (?{ '...' }) ) ) (?&y)+ }x; } print("\n");