// 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"\(20(\d{2}|x{2})((\.|-)([0-9]{2}|x{2}|KW(\d{2}|x{2})|Q(x|[1-4])|(([0-9]{2}|x{2})(\.|-)([0-9]{2}|x{2}))))?\)").unwrap();
let string = "20000002000
200 0
(2022.xx2000.xx)
(2022.xx) 2000.xx
(2020-20)
(20xx-12)
(20xx.xx-11)
(2002-KW00.00)
(2002-KW00)
(2022.KWxx)
(2021.KW09)
(2021.KW09)
(2021.02)
2022.Qx
2032.Q4
(2020.xx)
2022-Q1
2022 Test
Test 20xx
20202020
.Qx
KW23
KWxx
(20xx)
(.-Q4)
2000-
2000.
";
// 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/