// 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).*?course: (\w+)(?:(?!\bcourse\b).)*MyName\s+(\d+).*?").unwrap();
let string = "sometext
somemore text here
some other text
course: course1
Id Name marks
____________________________________________________
1 student1 65
2 student2 75
3 MyName 69
4 student4 43
course: course2
Id Name marks
____________________________________________________
1 student1 84
2 student2 73
8 student7 99
4 student4 32
course: course4
Id Name marks
____________________________________________________
1 student1 97
3 MyName 60
8 student6 82";
// 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/