[perl #132120] [REGEX] Accessing captures from another capture fails a match

2017-09-18 Thread Zoffix Znet via RT
On Mon, 18 Sep 2017 09:46:50 -0700, sml...@gmail.com wrote:
> This ticket can IMO be closed as 'rejected', but I'll leave it open
> for now in case I missed something obvious or in case you want to turn
> it into an RFC or similar.
> 
> 
> ---
> [1] http://design.perl6.org/S05.html#Subpattern_captures


I just didn't know of this feature. Thanks for clarifying.

Rejecting 


[perl #132120] [REGEX] Accessing captures from another capture fails a match

2017-09-18 Thread Zoffix Znet via RT
On Mon, 18 Sep 2017 09:46:50 -0700, sml...@gmail.com wrote:
> This ticket can IMO be closed as 'rejected', but I'll leave it open
> for now in case I missed something obvious or in case you want to turn
> it into an RFC or similar.
> 
> 
> ---
> [1] http://design.perl6.org/S05.html#Subpattern_captures


I just didn't know of this feature. Thanks for clarifying.

Rejecting 


[perl #132120] [REGEX] Accessing captures from another capture fails a match

2017-09-18 Thread Sam S. via RT
On Mon, 18 Sep 2017 09:00:54 -0700, c...@zoffix.com wrote:
> IRC: https://irclog.perlgeek.de/perl6/2017-09-18#i_15181575
> 
> We can use $0 here to refer to previous capture and regex matches:
> m: say "11" ~~ /(\d)[$0]/
> rakudo-moar 48a84d: OUTPUT: «「11」␤ 0 => 「1」␤»
> 
> But if we capture that match, the match fails:
> m: say "11" ~~ /(\d)([$0])/
> rakudo-moar 48a84d: OUTPUT: «Nil␤»

Not a bug.

Each `( )` capture represents a subpattern¹ that builds its own Match object, 
and inside the subpattern, `$/` refers to this subpattern's Match (which in 
your case doesn't have any captures) and not to the parent pattern's Match 
(which has the capture you meant to access).
(PS: Remember that `$0` is just an alias for `$/[0]`.)

I don't think there's a built-in way to access a parent pattern's Match object 
- you'll have to manually pass on the object in a variable or similar, like you 
already discovered in the linked IRC log.

This ticket can IMO be closed as 'rejected', but I'll leave it open for now in 
case I missed something obvious or in case you want to turn it into an RFC or 
similar.


---
[1] http://design.perl6.org/S05.html#Subpattern_captures


[perl #132120] [REGEX] Accessing captures from another capture fails a match

2017-09-18 Thread via RT
# New Ticket Created by  Zoffix Znet 
# Please include the string:  [perl #132120]
# in the subject line of all future correspondence about this issue. 
# https://rt.perl.org/Ticket/Display.html?id=132120 >


IRC: https://irclog.perlgeek.de/perl6/2017-09-18#i_15181575

We can use $0 here to refer to previous capture and regex matches:
m: say "11" ~~ /(\d)[$0]/
rakudo-moar 48a84d: OUTPUT: «「11」␤ 0 => 「1」␤»

But if we capture that match, the match fails:
m: say "11" ~~ /(\d)([$0])/
rakudo-moar 48a84d: OUTPUT: «Nil␤»