// 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\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|playlist\?|watch\?v=|watch\?.+(?:&|&);v=))([a-zA-Z0-9\-_]{11})?(?:(?:\?|&|&)index=((?:\d){1,3}))?(?:(?:\?|&|&)?list=([a-zA-Z\-_0-9]{34}))?(?:\S+)?").unwrap();
let string = "https://www.youtube.com/playlist?list=PL1eC1aP-LYNg2ya1ywPj0pipd0y2EWGEl
https://www.youtube.com/watch?v=4UcfECYbDYQ&index=1&list=PL1eC1aP-LYNg2ya1ywPj0pipd0y2EWGEl
https://youtu.be/4UcfECYbDYQ?list=PL1eC1aP-LYNg2ya1ywPj0pipd0y2EWGEl
https://www.youtube.com/watch?v=Svmor6ouuO4&index=4&list=PL1eC1aP-LYNg2ya1ywPj0pipd0y2EWGEl
https://www.youtube.com/watch?v=M44e92KoIaE
https://youtu.be/M44e92KoIaE
https://www.youtube.com/embed/videoseries?list=PL1eC1aP-LYNg2ya1ywPj0pipd0y2EWGEl";
// 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/