// 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)^(?=-.*D$|\d.*C$)-?(?=(?:\d,?){1,13}\.)(?:0|[1-9]\d{0,2}(?:,\d{3})*)\.\d{2} [DC]$").unwrap();
let string = "-0.48 D
-1.00 D
-2,000.00 D
-100,000.56 D
-100,000.00 D
-1,123,456.43 D
-1,123,456,000,000.43 D
-10,123,456,000,000.43 D
-1,123,456.43 C
-3,000,62.45 D
-03,000.45 D
-.23 D
0.23 C
1.00 C
2,000.00 C
100,000.56 C
100,000.00 C
1,123,456.43 C
1,123,456,000,000.43 C
10,123,456,000,000.43 C
";
// 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/