syntax s/ / /
Documentation for syntax
s/ / / assembled from the following types:
Substitutions are written similarly to matching, but the substitution operator has both an area for the regex to match, and the text to substitute:
s/replace/with/; # a substitution that is applied to $_~~ s/replace/with/; # a substitution applied to a scalar
The substitution operator allows delimiters other than the slash:
Note that neither the colon
: nor balancing delimiters such as
() can be substitution delimiters. Colons clash with adverbs such as
s:i/Foo/bar/ and the other delimiters are used for other purposes.
If you use balancing curly braces, square brackets, or parentheses, the substitution works like this instead:
s[replace] = 'with';
The right-hand side is now a (not quoted) Raku expression, in which
$/ is available as the current match:
= 'some 11 words 21';s:g[ \d+ ] = 2 * $/;.say; # OUTPUT: «some 22 words 42␤»
m// operator, whitespace is ignored in the regex part of a substitution.