// 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"(?s)(label\s\d{1,4}\sstart(\s*explanation)(.*?)up\sup\s*exit)").unwrap();
let string = "label 123 start
int
some other random text
exit
exit
label 576 start
int
some other random text
exit
exit
label 888 start
explanation jgfjgjgj
some random text
exit
up up
exit
label 902 start
explanation jgfjgjgj
some random text
exit
up up
exit
label 456 start
explanation jgfjgjgj
some random text
exit
up up
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/