// 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)(?:^----CAPITAL WORDS:\n|\G)(?!(----(?:MORE )?CAPITAL WORDS:))(\S.*)(?:\n(?!(?1))(\S.*))+\s*").unwrap();
let string = "Some random text before.
----CAPITAL WORDS:
first subheading
https://link1
https://link2
second subheading
https://link3
third subheading
https://link4
https://link5
https://link6
https://link7
----MORE CAPITAL WORDS:
Some random text after.
Some random text before.
----CAPITAL WORDS:
first subheading
https://link1
https://link2
----MORE CAPITAL WORDS:
second subheading
https://link3
third subheading
https://link4
https://link5
https://link6
https://link7
----MORE CAPITAL WORDS:
Some random text after.";
// 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/