// 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"(?<=^|\s)(?:(?:0|[1-9][0-9]{0,2}(?:,[0-9]{3})*))(?=\s|$)").unwrap();
let string = "So hopefully will match 1,234 and 23,322 and 1,234,567 and 12 but not 1,23,1 or ,,1111, or anything else silly.
213,213,213
16,587,684,324
654,674,684
6,764,324
65,647,534
8,743,213
313,546
576,476
55,455
5,789
1
12
123
4,565
089
0,457
004,457
ajdgasj kadfshk 4d 5 kdhkds 5
5 sdfsdf
0
sadfasdfkj 7,456,464,646 adsff 6,565,454";
// 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/