Re: subst :g and captures in the replacement

2020-04-19 Thread Richard Hainsworth
Yary, I tried your examples out in REPL after reading Tobias and Timo's responses. After the second example, I tried outputting theĀ  result of '$/' which contains theĀ  whole capture from the last regex match. My result was > 'fosdffgg'.subst(/(f+)/,'( ' ~ $0 ~ ' )',:g) ( f )osd( f )gg > $/

Re: subst :g and captures in the replacement

2020-04-19 Thread Tobias Boege
On Sun, 19 Apr 2020, yary wrote: > How would one do s/(.+),(.+)/$1,$0/ using .subst ? > -y You can pass a code block as the second argument which assembles the replacement text. The block is evaluated anew for every substitution and it has access to the latest captures: say .subst(/(.*) ','

Re: subst :g and captures in the replacement

2020-04-19 Thread yary
How would one do s/(.+),(.+)/$1,$0/ using .subst ? -y On Sun, Apr 19, 2020 at 6:21 PM Tobias Boege wrote: > On Sun, 19 Apr 2020, yary wrote: > > Question from today's Raku meetup. This works in a way I expect > > > > > 'fosdffgg'.subst(/f+/,"( "~ * ~" )", :g); > > ( f )osd( ff )gg > > > > This

Re: subst :g and captures in the replacement

2020-04-19 Thread Tobias Boege
On Sun, 19 Apr 2020, yary wrote: > Question from today's Raku meetup. This works in a way I expect > > > 'fosdffgg'.subst(/f+/,"( "~ * ~" )", :g); > ( f )osd( ff )gg > > This one, $0 gets the single f each time > > > 'fosdffgg'.subst(/(f+)/,"( $0 )", :g); > ( f )osd( f )gg > > Bug or

Re: subst :g and captures in the replacement

2020-04-19 Thread Timo Paulssen
Hi Yary, in the first example you've got a WhateverCode, but in the second one you're actually just passing a string to subst, i.e. you're evaluating $0 before subst is even called. Check this as well: > raku -e '"whoa" ~~ /(.)/; say \'fosdffgg\'.subst(/(f+)/,"( $0 )", :g)' > ( w )osd( w )gg

subst :g and captures in the replacement

2020-04-19 Thread yary
Question from today's Raku meetup. This works in a way I expect > 'fosdffgg'.subst(/f+/,"( "~ * ~" )", :g); ( f )osd( ff )gg This one, $0 gets the single f each time > 'fosdffgg'.subst(/(f+)/,"( $0 )", :g); ( f )osd( f )gg Bug or misunderstanding on my part? -y