lazy_regex

Macro regex_captures_iter

Source
regex_captures_iter!() { /* proc-macro */ }
Expand description

Returns an iterator that yields successive non-overlapping matches in the given haystack. The iterator yields values of type regex::Captures.

Example (adapted from the regex crate):

let hay = "'Citizen Kane' (1941), 'The Wizard of Oz' (1939), 'M' (1931).";
let mut movies = vec![];
let iter = regex_captures_iter!(r"'([^']+)'\s+\(([0-9]{4})\)", hay);
for (_, [title, year]) in iter.map(|c| c.extract()) {
    movies.push((title, year.parse::<i64>().unwrap()));
}
assert_eq!(movies, vec![
    ("Citizen Kane", 1941),
    ("The Wizard of Oz", 1939),
    ("M", 1931),
]);