Skip to content

Commit

Permalink
Explain s[...] = replacement form of substitution
Browse files Browse the repository at this point in the history
  • Loading branch information
moritz committed Jun 30, 2017
1 parent 6372a29 commit 9a369c7
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion doc/Language/regexes.pod6
Expand Up @@ -775,7 +775,19 @@ Note that neither the colon C<:> nor balancing delimiters such as C<{}> or
C<()> can be substitution delimiters. Colons clash with adverbs such as C<s:i/Foo/bar/>
and the other delimiters are used for other purposes.
Like the C<m//> operator, whitespace is ignored in general. Comments, as in
If you use balancing brackets, the substitution works like this instead:
s[replace] = 'with';
The right-hand side is now a (not quoted) Perl 6 expression, in which C<$/>
is available as the current match:
$_ = 'some 11 words 21';
s:g[ \d+ ] = 2 * $/;
.say; # OUTPUT: «some 22 words 42␤»
Like the C<m//> operator, whitespace is ignored in the regex part of a
substitution. Comments, as in
Perl 6 in general, start with the hash character C<#> and go to the end of
the current line.
Expand Down

0 comments on commit 9a369c7

Please sign in to comment.