// 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"(?mx)^(
( # GENERAL before . (Dot)
(?!\w+\?) # DO NOT MATCH if contains ?
[\w\]\)]+ # Word, ] or ) characters 1 or more times
)|
(?:\((\w+)\))| # BRACKETS ()
([\w\]\)]+(?![?*+])) # BEFORE . (Dot) with ?, * or +
)").unwrap();
let string = "abcdef.*g[0abc]{0,5}hi # abcdef
]1234vac.*12345 # ]1234vac
)1234vac.*12345 # )1234vac
(abc)+123 # abc
12345[abcde]+12345 # 12345
123?456 # 12
123\\?456 # 123?456
# --- No Prefix ---
[A-z]+12345
(1234vac.*12345
[a-z]+";
// 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/