Documentation for method indices
assembled from the following pages:
Class: Str §
From Str
(Str) method indices §
Defined as:
multi method indices(Str: Str , :i(:), :m(:), : --> List)multi method indices(Str: Str , Int , :i(:), :m(:), : --> List)
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)»