// 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)((?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|Jun(?:e)?|Jul(?:y)?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|(Nov|Dec)(?:ember)?)(\s)([1,2][\d]|[1-9]|30|31)(\s))?(\b[\d]|10|11|12):[0-5][0-9]\s(AM|PM)").unwrap();
let string = "March 9 12:31 AM and March 10 7:30 AM
March 11 7:30 AM and March 12 10:30 AM
Mar 31 9:00 PM and Apr 1 12:39 AM
March 31 10:11 PM and April 1 5:23 AM
7:45 PM and 10:30 PM
May 3 4:41 PM PDT and May 4 12:19 AM PDT
March 31 10:71 PM and April 1 5:23 AM
27:45 PM and 10:80 PM
May 3 4:41 PM PDT and May 41 12:19 AM PDT";
// 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/