// 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)^[1-9]\d{0,3} ?[a-zA-Z]?(?: ?[/-] ?[1-9]\d{0,3} ?[a-zA-Z]?)?$").unwrap();
let string = "############# valid ##########
12
12a
12A
12 A
12 a
12 b
12 z
121 b
56/58
56/58a
56-58
56 - 58
56-58a
1234
1234 a
56/58a
18a - 19b
18a-19b
############# not valid ##########
12345
25-ab
12ü
12_
asdfghjklöqwertzuioyxcvbnm
12!\"§$$%&/()
a2
a2
13àâäèéêë
0
123aaa123,
123 aaa 123
1 a 1
1a 1'
1a1
13àâäèéêë
00 a
a a
00a
0a
12 ab 12";
// 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/