// 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#"https?://(www\.|m\.)?(reddit\.com|preview\.redd\.it|i\.redd\.it|redd\.it)/(((?!([\"'<])).)*)"#).unwrap();
let string = "https://reddit.com/r/lorem
https://preview.redd.it/r/ipsum
https://i.redd.it/r/dolor
https://redd.it/r/sit
https://www.reddit.com/r/lorem↵
https://www.preview.redd.it/r/ipsum↵
https://www.i.redd.it/r/dolor↵
https://www.redd.it/r/sit
https://m.reddit.com/r/lorem↵
https://m.preview.redd.it/r/ipsum↵
https://m.i.redd.it/r/dolor↵
https://m.redd.it/r/sit
https://no-reddit.com/r/lorem
";
// 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/