indices
ErrorsCollection

indices

Synthesised documentation from type/Str

From type/Str

See Original text in context

multi method indices(Str:D: Str:D $needle:i(:$ignorecase), :m(:$ignoremark), :$overlap --> List:D)
multi method indices(Str:D: Str:D $needleInt:D $start:i(:$ignorecase), :m(:$ignoremark), :$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)␤»

Since Rakudo version 2020.02, if the optional named parameter :ignorecase, or :i, is specified, the search for $needle ignores the distinction between upper case, lower case and title case letters.

say "banAna".indices("a");              # OUTPUT:«(1 5)␤» 
say "banAna".indices("a":ignorecase); # OUTPUT:«(1 3 5)␤»

Since Rakudo 2020.02, if the optional named parameter :ignoremark, or :m, is specified, the search for $needle only considers base characters, and ignores additional marks such as combining accents.

say "tête-à-tête".indices("te");              # OUTPUT:«(2 9)␤» 
say "tête-à-tête".indices("te":ignoremark); # OUTPUT:«(0 2 7 9)␤»