// 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"(?mi)(?:(.*)(?:https:|http:)?\/\/)?(?:(.*)(?:www\.youtube\.com\/(?:embed\/|watch\?v=)|youtu\.be\/|youtube\.googleapis\.com\/v\/)(?<YoutubeID>[a-z0-9-_]{11,12})|(?:vimeo\.com\/|player\.vimeo\.com\/video\/)(?<VimeoID>[0-9]+))").unwrap();
let string = "https://www.youtube.com/embed/123456789012
https://www.youTUbe.com/embed/123456789012
http://www.youtube.com/watch?v=My2FRPA3Gf8
htTp://www.youtube.com/watch?V=My2FRPA3Gf8
http://youtu.be/My2FRPA3Gf8
http://youTU.be/My2FRPA3Gf8
https://www.youtu.be/embed/123456789012
https://youtube.googleapis.com/v/123456789012
https://youtube.googleAPis.com/v/123456789012
https://youtube.googleapis.com/embed/123456789012
https://www.youtube.com/embed/123456789012
http://www.youtube.com/embed/123456789012
//www.youtube.com/embed/123456789012
www.youtube.com/embed/123456789012
http://vimeo.com/25451551
http://player.vimeo.com/video/25451551
https://player.vimeo.com/video/6969232737373733383782383273287328327342873
http://player.vimeo.com/video/6969
http://plaser.vimeo.com/video/6969
";
// 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/