Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document @(code) interpolation in regex #3317

Merged
merged 2 commits into from Apr 8, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions doc/Language/regexes.pod6
Expand Up @@ -1894,6 +1894,9 @@ pattern, which may be summarized as follows:

=end table

Instead of the C<$> sigil, you may use the C<@> sigil for array interpolation.
See below for how this works.

X<|regex, $variable>X<|regex, $(code)>
Let's start with the first two syntactical forms: C«$variable» and C«$(code)».
These forms will interpolate the stringified value of the variable or the
Expand Down Expand Up @@ -2017,6 +2020,15 @@ regexes. Just as with ordinary C<|> interpolation, the longest match succeeds:
my @a = '2', 23, rx/a.+/;
say ('b235' ~~ / b @a /).Str; # OUTPUT: «b23»

If you have an expression that evaluates to a list, but you do not want to
assign it to an @-sigiled variable first, you can interpolate it with
C<@(code)>. In this example, both regexes are equivalent:

my %h = a => 1, b => 2;
my @a = %h.keys;
say S:g/@(%h.keys)/%h{$/}/ given 'abc'; # OUTPUT: «12c>
say S:g/@a/%h{$/}/ given 'abc'; # OUTPUT: «12c>

zopsicle marked this conversation as resolved.
Show resolved Hide resolved
The use of hashes in regexes is reserved.

=head2 Regex boolean condition check
Expand Down