// 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)^\[([^][\r\n]*)][^\S\r\n]+([^:\r\n]+):(.*(?:\r?\n {4}.*)*)").unwrap();
let string = "[chat] somebody: this is some text that needs to be matched.
it continues on this line with four spaces at the bottom
and its also on this line.
It should not match this line
[chat] somebody: this is more text, but only one line.
This should not be matched";
// 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/