// 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)\w+ \((?:[1-9]|[1234][0-9])\)(?:, )?").unwrap();
let string = "I can not find a working regular expression to match the strings followed by a number from 1 to 49 in braces, in a list dividing the pairs by comma:
alpha (1), beta (12), gamma (37), delta (49), epsilon (55), zeta (64)
but also in random order and amount of pairs like
zeta (64), alpha (1), gamma (37), beta (12), delta (49), epsilon (55), eta (48), theta (26)
and also random numbers like
zeta (11), gamma (71), beta (49), delta (52), epsilon (99), alpha (33)
I'm looking for an endresult showing only the pairs with a number lower as 49 like
alpha (1), beta (12), gamma (37), delta (49)
alpha (1), gamma (37), beta (12), delta (49), eta (48), theta (26)
zeta (11), beta (49), alpha (33)";
// 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/