// 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)<img\s+[^>]*?src=["\']?([^"\'> ]+)["\']?[^>]*>"#).unwrap();
let string = "<!-- works -->
<div><img class=\"img-responsive\" src=\"/images/dir%20with%20spaces/file%20with%20spaces.png?ver=1.0\" /></div>
<div><img class=\"img-responsive\" src=\"/images/dir/file-with-accents-áépi.png?ver=1.0\" /></div>
<div><img class=\"img-responsive\" src=unquotedimage.jpg /></div>
<div><img class=\"img-responsive\" src=unquotedimagewithdoublequote\".jpg /></div>
<div><img class=\"img-responsive\" src=unquotedimagewithsinglequote'.jpg /></div>
<div><img class=\"img-responsive\" src=unquotedimagewithcolon:.jpg /></div>
<!-- not working -->
<div><img class=\"img-responsive\" src=\"/images/dir with spaces/file with spaces.png?ver=1.0\" /></div>
";
// 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/