// 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)(?:o|dp(?:\/[^/]+)?|gp\/product(?:\/[^/]+)?)\/([A-Z0-9]{10})").unwrap();
let string = "http://www.amazon.com/PlayStation-2-Console-Slim-Black/dp/B000TLU67W/ref=sr_1_4?ie=UTF8&qid=1389314719&sr=8-4&keywords=playstation+1
http://www.amazon.com/PlayStation-2-Console-Slim-Black/dp/B000TLU67W
http://www.amazon.com/gp/product/C0FF33CUP5
http://www.amazon.com/gp/product/CoffeeCups/C0FF33CUP5
http://www.amazon.com/o/C0FF33CUP5
http://www.amazon.com/dp/C0FF33CUP5
http://www.amazon.com/CoffeeCups/dp/C0FF33CUP5
http://www.amazon.com/CoffeeCups/dp/some-text/C0FF33CUP5
http://www.amazon.com/CoffeeCups/dp/B000TLU67W/ref=sr_1_4?ie=UTF8&qid=1389314719&sr=8-4&keywords=playstation+1";
// 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/