// 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)^(?P<name>[\w\-\.]+)-(?P<version>v?\d+(\.\d+)?(\.\d+)?(-[\w\-]+(\.[\w\-]+)*)?(\+[\w\-]+(\.[\w\-]+)*)?)(?P<ext>\.[\w\-]+)$").unwrap();
let string = "ansi-escapes-4.3.1.tgz
babel-eslint-10.1.0.tgz
chance-1.1.7.tgz
cli-cursor-3.1.0.tgz
eslint-7.13.0.tgz
faker-5.1.0.tgz
forever-monitor-3.0.1.tgz
fs-extra-9.0.1.tgz
lorem-ipsum-2.0.3.tgz
micromatch-4.0.2.tgz
mongoose-5.10.13.tgz
puppeteer-5.4.1.tgz
puppeteer-extra-3.1.15.tgz
puppeteer-extra-plugin-stealth-2.6.3.tgz
random-email-1.0.3.tgz
random-useragent-0.5.0.tgz
random-words-1.1.1.tgz
slice-ansi-4.0.0.tgz
uuid-8.3.1.tgz
validator-13.1.17.tgz
wrap-ansi-7.0.0.tgz
font-awesome-5.11.2.tgz
react-dom-16.13.1.tgz
bootstrap-4.5.2.tgz
moment-duration-format-2.3.2.tgz
imagesloaded-4.1.tgz
flickity-2.0.tgz
lomster-1.tgz
unicorn-1.2.3-alpha.10.beta.0.tgz
rainbow-v1.1.1.tgz
object.assign-4.1.4.tgz
hello_world-0.0.3.tgz
typescript-package-1-1.0.2.tgz
";
// 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/