// 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"(?!.*\/)(.*)-(([^-]+)-([0-9]+))-([^.]+)(\.chi\.zst)").unwrap();
let string = "http://localhost/
http://localhost/packages/a/
http://localhost/packages/b/
http://localhost/packages/c/
http://localhost/packages/core/
http://localhost/packages/d/
http://localhost/packages/e/
http://localhost/packages/f/
http://localhost/packages/g/
http://localhost/packages/h/
http://localhost/packages/i/
http://localhost/packages/j/
http://localhost/packages/k/
http://localhost/packages/l/
http://localhost/packages/m/
http://localhost/packages/meta/
http://localhost/packages/n/
http://localhost/packages/o/
http://localhost/packages/p/
http://localhost/packages/q/
http://localhost/packages/r/
http://localhost/packages/s/
http://localhost/packages/t/
http://localhost/packages/u/
http://localhost/packages/v/
http://localhost/packages/w/
http://localhost/packages/x/
http://localhost/packages/y/
http://localhost/packages/z/
http://localhost/packages/a/atkmm-2.28.2-2-x86_64.chi.zst
http://localhost/packages/a/atom-1.61.0beta0-2-x86_64.chi.zst
http://localhost/packages/a/atril-1.26.0-1-x86_64.chi.zst
http://localhost/packages/a/attica-5.94.0-1-x86_64.chi.zst
http://localhost/packages/a/attr-2.5.1-2-x86_64.chi.zst
http://localhost/packages/a/aubio-0.4.9-13-x86_64.chi.zst
http://localhost/packages/a/aubio-0.4.9-7-x86_64.chi.zst
http://localhost/packages/a/audacious-4.0.5-1-x86_64.chi.zst
http://localhost/packages/a/audacious-plugins-4.0.5-1-x86_64.chi.zst
http://localhost/packages/a/audacity-1:2.4.1-7-x86_64.chi.zst
http://localhost/packages/a/audiofile-0.3.6-6-x86_64.chi.zst
http://localhost/packages/a/audit-3.0.8-1-x86_64.chi.zst
http://localhost/packages/a/augeas-1.12.0-2-x86_64.chi.zst
http://localhost/packages/a/auracle-git-r366.8739929-4-x86_64.chi.zst
";
// result will be a tuple containing the start and end indices for the first match in the string
let result = regex.captures(string);
let (start, end) = match result {
Some((s, e)) => (s, e),
None => {
// ...
}
};
println!("{}", &string[start, end]);
}
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/