// 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)(err\s*?\d{1})|[^\d]\s+(\d{3})(?:$|\s+(?!\d))").unwrap();
let string = "The below items should match:
-----------------------------
123
456 123
123 324 324
Match the number in this sentence 123 as well
999
The below items should NOT match:
---------------------------------
1234
12345
123456
1234567
£123
$456
Err404
ERR404
err404
Err 404
ERR 404
err 404
there is err 404 on page
this err 1232222222222 as well
a string 12323 like this
asd
4444333322221111
4444 3333 2222 1111
Err123
02012341234
920 1234 1234";
// 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/