Course of Raku / Regexes and grammars / Regexes / Substitution and replacement / The substitution operator

Quiz — The s/// operator

What does the following program print?

my $s = 'one two two';
$s ~~ s/two/three/;
say $s;
1one three two
0one three three
0one two two
0three two two

Without the :g adverb, s/// replaces only the first match. So just the first two becomes three, giving one three two. With s:g/// both occurrences would change.

Course navigation

The substitution operator   |   Captures in the replacement