// 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"(?im)^(((1)st?|(2)nd?|(3)rd?|([4-9])th?)|(([0-9]*)(1[0-9])th?)|(([0-9]*[02-9])((1)st?|(2)nd?|(3)rd?|([04-9])th?)))$").unwrap();
let string = "// ordinals
1st
22nd
333rd
4444th
2500th
// teens
11th
12th
13th
14th
15th
16th
17th
18th
19th
// teens - hundreds
111th
112th
113th
114th
115th
116th
117th
118th
119th
// teens - wrong suffix
11st
12nd
13rd
111st
112nd
113rd
// uppercase
1ST
22ND
333RD
444TH
// wrong suffix (do nothing)
0th
26st
31th
21rd
29nd";
let substitution = "$3$4$5$6$8$9$11$13$14$15$16";
// result will be a String with the substituted value
let result = regex.replace_all(string, substitution);
println!("{}", result);
}
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/