expression

Regex::captures_iter: extract repeated records

Extract the fields of each nonoverlapping match. This search does not establish that all remaining text follows the same record grammar. This example uses the external regex crate; see the staged Cargo manifest. Expected stdout (not executed): pen 2 book 3 Common mistake: Silently accepting ignored text when every record must be validated.

Formal Syntax & Structure

rust syntaxrust
re.captures_iter(text)

Working Example

Example Snippetrust
fn main() {    let re = regex::Regex::new(r"([a-z]+):([0-9]+)").unwrap();    for c in re.captures_iter("pen:2 book:3") { println!("{} {}", &c[1], &c[2]); }}
Rust Reference