// 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"(?mx)(?<!d)(?:
(?:(?:0?[1-9]|[12]\d)|3[01])\s?[./:-][\s.]?(?:0?[13578]|1[02]|J(?:an(?:uar)?|uli?)|M(?:ärz?|ai)|Aug(?:ust)?|Dez(?:ember)?|Okt(?:ober)?)\s?(?:[./:-][\s.]?)?[1-9]\d\d\d|
(?:(?:0?[1-9]|[12]\d)|30)\s?[./:-][\s.]?(?:0?[13-9]|1[012]|J(?:an(?:uar)?|u[nl]i?)|M(?:ärz?|ai)|A(?:pr(?:il)?|ug(?:ust)?)|Sep(?:tember)?|(?:Nov|Dez)(?:ember)?|Okt(?:ober)?)\s?(?:[./:-][\s.]?)?[1-9]\d\d\d|
(?:0?[1-9]|[12]\d)\s?[./:-][\s.]?(?:0?2|Fe(?:b(?:ruar)?)?)\s?(?:[./:-][\s.]?)?[1-9]\d(?:[02468][048]|[13579][26])|
(?:0?[1-9]|[12][0-8])\s?[./:-][\s.]?(?:0?2|Fe(?:b(?:ruar)?)?)\s?(?:[./:-][\s.]?)?[1-9]\d\d\d
)(?!\d)").unwrap();
let string = "12.12.2021
09. Juni 1997
01.Aug.1995
27.06. 1997
29.02.1996
21. 01. 1999
28.05. 1996
07..4..1995
20:03:1998
9.4.1997
14 .03 - 1995
Month regex is tested at https://regex101.com/r/tClRRs/2
(?:J(?:an(?:uar)?|u[nl]i?)|Fe(?:b(?:ruar)?)?|M(?:ärz?|ai)|A(?:pr(?:il)?|ug(?:ust)?)|Sep(?:tember)?|(?:Nov|Dez)(?:ember)?|Okt(?:ober)?)
Taking out Feb: (?:J(?:an(?:uar)?|u[nl]i?)|M(?:ärz?|ai)|A(?:pr(?:il)?|ug(?:ust)?)|Sep(?:tember)?|(?:Nov|Dez)(?:ember)?|Okt(?:ober)?)
";
// 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/