Documentation for method subst-mutate

Documentation for method subst-mutate, assembled from the following types:

class Str

From Str

(Str) method subst-mutate

Where subst returns the modified string and leaves the original unchanged, it is possible to mutate the original string by using subst-mutate. If the match is successful, the method returns a Match object representing the successful match; if :g (or :global) argument is used, returns a List of Match objects. If no matches happen, returns Any.

my $some-string = "Some foo";
my $match = $some-string.subst-mutate(/foo/"string");
say $some-string;  # OUTPUT: «Some string␤» 
say $match;        # OUTPUT: «「foo」␤» 
$some-string.subst-mutate(/<[oe]>/'':g); # remove every o and e, notice the :g named argument from .subst