// 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)(<iframe.*?src=([\"\'])https?:\/\/w{0,3}.?youtube.com.*?(\2).*?\>)(.*?)(\<\/iframe\>)"#).unwrap();
let string = "<iframe src=\"http://youtube.com\" width=\"100\" height=\"200\">data</iframe>
<iframe src='http://youtube.com' width=\"100\" height=\"200\">data</iframe>
<iframe width=\"100\" src='http://youtube.com' width=\"100\"></iframe>
<iframe src=\"https://youtube.com\" width=\"100\" height=\"200\">data</iframe>
<iframe src='https://youtube.com' width=\"100\" height=\"200\">data</iframe>
<iframe width=\"100\" src='https://youtube.com\" width=\"100\">data</iframe>
<iframe width=\"560\" height=\"315\" src=\"https://www.youtube.com/embed/tvrXet3Lx4U\" frameborder=\"0\" allowfullscreen></iframe>
<iframe width=\"560\" height=\"315\" src=\"https://www.youtube.com/embed/tvrXet3Lx4U\" frameborder=\"0\" allowfullscreen>data</iframe>";
// 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/