Skip to content

Commit 7925341

Browse files
committed
Add the S/// section from operators to regexes
1 parent 56ce35b commit 7925341

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

doc/Language/regexes.pod6

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,6 +1373,22 @@ that their regular expression needs to match every piece of data in the line,
13731373
including what they want to match. Write just enough to match the data you're
13741374
looking for, no more, no less.
13751375
1376+
=head2 X«C<S///> non-destructive substitution»
1377+
1378+
say S/o .+ d/new/ with 'old string'; # OUTPUT: «new string»
1379+
S:g/« (.)/$0.uc()/.say for <foo bar ber>; # OUTPUT: «Foo␤Bar␤Ber»
1380+
1381+
C<S///> uses the same semantics as the C<s///> operator, except
1382+
it leaves the original string intact
1383+
and I<returns the resultant string> instead of C<$/> (C<$/> still being set
1384+
to the same values as with C<s///>).
1385+
1386+
B<Note:> since the result is obtained as a return value, using this
1387+
operator with the C<~~> smartmatch operator is a mistake and will issue a
1388+
warning. To execute the substitution on a variable that isn't the C<$_> this
1389+
operator uses, alias it to C<$_> with C<given>, C<with>, or any other way.
1390+
Alternatively, use the L«C<.subst> method|/routine/subst».
1391+
13761392
=head1 X<Tilde for nesting structures|regex, tilde; regex, ~>
13771393
13781394
The C<~> operator is a helper for matching nested subrules with a

0 commit comments

Comments
 (0)