expression

RegexSet: classify with multiple patterns

Check multiple independent patterns and report their matching indices. This does not return capture groups or match spans. This example uses the external regex crate; see the staged Cargo manifest. Expected stdout (not executed): [1, 2] Common mistake: Expecting RegexSet to extract the matching substring.

Formal Syntax & Structure

rust syntaxrust
RegexSet::new(patterns); set.matches(text)

Working Example

Example Snippetrust
fn main() {    let set = regex::RegexSet::new(["error", "warning", r"[0-9]+"]).unwrap();    let indices: Vec<_> = set.matches("warning 12").iter().collect();    println!("{:?}", indices);}
Rust Reference