std-method

str::match_indices

Iterate over non-overlapping matches with their starting byte offsets. Expected stdout (not executed): 0:ش 3:ش Common mistake: Expecting overlapping matches or scalar indices.

Formal Syntax & Structure

rust syntaxrust
text.match_indices(pattern)

Working Example

Example Snippetrust
fn main() {    for (i, part) in "ش ش".match_indices('ش') { println!("{i}:{part}"); }}
Rust Reference