// 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)(?:(?P<Day1>\d{1,2})(?:\W*(?P<Month1>[A-Z][a-z]*\b))|(?:(?P<Month2>[A-Z][a-z]*\b)\W*)(?:(?P<Day2>\d{1,2})(?:\b|th|st|nd))?|(?P<Month3>\d{1,2})\W+(?P<Day3>\d{1,2})|(?P<Month4>\d{1,2}))?\W+?(?P<Year>\d{2,4}(?=$|;))").unwrap();
let string = "04/20/2009
04/20/09
4/20/09
4/3/09
Mar-20-2009
Mar 20, 2009
March 20, 2009
Mar. 20, 2009
Mar 20 2009;
20 Mar 2009
20 March 2009
20 Mar. 2009
20 March, 2009
Mar 20th, 2009
Mar 21st, 2009
Mar 22nd, 2009
Feb 2009
Sep 2009
Oct 2010
6/2008
12/2009
2009
2010";
// 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/