On Fri, Mar 19, 2021 at 6:12 PM yary <not....@gmail.com> wrote:
>
> I don't know how to get the result.

> DB<1> $word = qr/(\w+)/;
> DB<2> $AwithB = qr/$word with $word/
> DB<3> $_ = 'Interpolating regexes with arbitrary captures is fun!'
> DB<4> x /$AwithB.*is $word/

A Raku equivalent:

my $word = '(\w+)';
my $AwithB = "$word ' with ' $word";
my $regex = "$AwithB .* 'is ' $word";
$_ = 'Interpolating regexes with arbitrary captures is fun!';

.say for m/<top=$regex>/.<top>.pairs;

displays:

 0 => 「regexes」
 1 => 「arbitrary」
 2 => 「fun」

----

> Raku example:
>
> my $word = /(\w+)/;
> my $AwithB = /$word' with '$word/;

If you interpolate by using `$abc...` or `<$abc...>` instead of `<abc...>`,
Raku will by default not capture. And the non-capturing is nested, so
throwing away those captures also throws away the corresponding
capture within `$word`.

> Where my expectation differs from the behavior in my example
> is Raku's discarding the capture groups of the interpolated regexes.

It only discards them if you tell it to discard them.

If a `<...>` construct begins with a letter, it'll capture. If not, it won't.

--
love, raiph

Reply via email to