// 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)SMR_.*_(.*)_GRID_(?P<Model>[a-zA-Z]+)_.*").unwrap();
let string = "RV_Exp_CX_GRID_08OCT18.dat
RV_Exp_JT_GRID_07NOV18.dat
RV_Exp_OPEL_WB_GRID_21NOV18.dat
RV_Ref_U_GRID_07NOV18.dat
SMR_Exp_CX_GRID_D_11OCT18txt
SMR_Exp_CX_GRID_E_30JUL18txt
SMR_Exp_CX_GRID_JS_07AUG18txt
SMR_Exp_CX_GRID_JT_17SEP18txt
SMR_Exp_GRID_D_07NOV18txt
SMR_Exp_GRID_E_05OCT18txt
SMR_Exp_GRID_JS_08JAN19txt
SMR_Exp_GRID_JT_07NOV18txt
SMR_Ref_GRID_D_07NOV18txt
SMR_Ref_GRID_E_05OCT18txt
SMR_Ref_GRID_JS_08JAN19txt
SMR_Ref_GRID_JT_07NOV18txt
SMR_WB_Exp_GRID_D_14NOV18txt
SMR_WB_Exp_GRID_JS_20FEB19txt
SMR_WB_Exp_GRID_JT_14NOV18txt";
// 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/