expression

Unicode matching reports byte offsets

String matches start and end at UTF-8 boundaries. Offsets count bytes, not displayed letters or grapheme clusters. This example uses the external regex crate; see the staged Cargo manifest. Expected stdout (not executed): 2 8 3 Common mistake: Treating a byte index as a character index.

Formal Syntax & Structure

rust syntaxrust
m.start(); m.end(); m.as_str()

Working Example

Example Snippetrust
fn main() {    let re = regex::Regex::new("لام").unwrap();    let m = re.find("سلام").unwrap();    println!("{} {} {}", m.start(), m.end(), m.as_str().chars().count());}
Rust Reference