// 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)([M,F]\/\d{2}\/((\d{1}((\')|(\’))?(([0,2-9]|1[0-1]?)((\")|(\'\')|(\”))?)?)|\d{1,3}cm|[1-2]m(\d{1,2}(cm)?)?)\s?\[\d{2,3}\s?(lbs|kg)\s?to\s?\d{2,3}\s?(lbs|kg)\]\s?\(((\d{1,2}\s?years?)|(([2-9]|1[0-1]?)\s?months?)|(\d{1,2}\s?years?(\;|\,)?\s?([0,2-9]|1[0-1]?)\s?months?)|(([2-9]|1[0-1]?)\s?weeks?))\)\s?(\s?\+\s?\(([DSBO]{1}:\s?(\d{2,3})\s?(lbs|kg)(\;|\,))?\s?([DSBO]{1}:\s?(\d{2,3})\s?(lbs|kg)(\;|\,))?\s?([DSBO]{1}:\s?(\d{2,3})\s?(lbs|kg)(\;|\,))?\s?[DSBO]{1}:\s?(\d{2,3})\s?(lbs|kg)\))?.*)|(^\[Meta\].*)"#).unwrap();
let string = "
M/20/5'10\" [150lbs to 180lbs] (2 years; 6 months) + (B: 300lbs; S: 410lbs; D: 480lbs)
F/26/5'2\" [52kg to 59kg] (5 years)
M/35/6'3\" [203lbs to 175lbs] (7 months) - Additional comments here
M/20/5'10\" [150lbs to 180lbs] (2 years; 6 months) + (B: 300lbs; S: 410lbs; D: 480lbs) ";
// 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/