// include the latest version of the regex crate in your Cargo.toml
extern crate regex;
use regex::Regex;
fn main() {
let regex = Regex::new(r"(?m)(n|an_nh)_(vc_v|naca_(i|E[1-4]|k_[1-4][1-4]))").unwrap();
let string = "Should match:
an_nh_naca_i
an_nh_naca_k_12
an_nh_naca_k_21
an_nh_naca_k_23
an_nh_naca_k_32
an_nh_naca_k_34
an_nh_naca_k_43
an_nh_naca_k_41
an_nh_naca_k_14
an_nh_naca_E1
an_nh_naca_E2
an_nh_naca_E3
an_nh_naca_E4
an_nh_vc_v
n_naca_i
n_naca_k_12
n_naca_k_21
n_naca_k_23
n_naca_k_32
n_naca_k_34
n_naca_k_43
n_naca_k_41
n_naca_k_14
n_naca_E1
n_naca_E2
n_naca_E3
n_naca_E4
n_vc_v
Should not match:
an_nh_naca_F1_3n_i
an_nh_naca_F1_3n_o
n_naca_F1_3n_i
n_naca_F1_3n_o";
// result will be an iterator over tuples containing the start and end indices for each match in the string
let result = regex.captures_iter(string);
for mat in result {
println!("{:?}", mat);
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Rust, please visit: https://docs.rs/regex/latest/regex/