// 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"(?mi)(^\w+\s?\D+)\s?(\d+[,\d+]*)\s?(\d+[,\d+]*)\s?(\d+[,\d+]*)\s?(\d+[,\d+]*)\s?(\d+[,\d+]*)\s?").unwrap();
let string = "Weapon Type/Force Used 2000 2001 2002 2003 2004 5-Year Total
Personal Weapons 12,945 17,830 20,636 21,933 25,050 98,394
None 2,702 3,114 2,974 3,294 4,176 16,260
Other 1,775 2,311 2,332 2,420 2,842 11,680
Knife/Cutting Instrument 1,511 2,082 2,080 2,445 2,852 10,970
Handgun 307 376 398 430 497 2,008
Blunt Object 283 404 394 455 469 2,005
Firearm (type not stated) 94 131 103 135 146 609
Other Firearm 74 107 92 155 154 582
Explosives 145 139 93 89 95 561
Motor Vehicle 43 52 46 59 71 271
Fire/Incendiary Device 36 34 42 36 88 236
Rifle 23 33 33 24 37 150
Shotgun 15 24 30 19 24 112
Drugs/Narcotics/Sleeping Pills 9 4 8 14 6 41
Poison 1 8 4 11 16 40
Asphyxiation 2 1 3 6 2 14
";
// 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/