// 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)^room \d+(?:\n(?!room \d|service prov).*)*\nservice prov.*(?:\n(?!room|exit).*)*\nexit$").unwrap();
let string = "room 31
name \"Bob\"
no TV outlet 49
exit
room 5
name \"Ted\"
service prov 10.1
outlet 49-50,52
exit
room 80
name \"Alice\"
outlet 49-50,52
dead outlet 1-20
exit
room 50
name \"Tim\"
outlet 49
exit
room 51
name \"Sue\"
service prov 10.2.0
outlet 49
exit";
// 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/