method indices

Documentation for method indices assembled from the following types:

class Str

From Str

(Str) method indices

Defined as:

multi method indices(Str:D: Str:D $needle, :$overlap --> List:D)
multi method indices(Str:D: Str:D $needle, Int:D $start, :$overlap --> List:D)

Searches for all occurrences of $needle in the string starting from position $start, or zero if it is not specified, and returns a List with all offsets in the string where $needle was found, or an empty list if it was not found.

If the optional parameter :overlap is specified the search continues from the index directly following the previous match, otherwise the search will continue after the previous match.

say "banana".indices("a");              # OUTPUT: «(1 3 5)␤»
say "banana".indices("ana");            # OUTPUT: «(1)␤»
say "banana".indices("ana", :overlap);  # OUTPUT: «(1 3)␤»
say "banana".indices("ana", 2);         # OUTPUT: «(3)␤»