// 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"/*.mkv").unwrap();
let string = "folder.jpg
metadata
Stargate SG-1 S01E01-E02 Children of the Gods.mkv
Stargate SG-1 S01E03 The Enemy Within.mkv
Stargate SG-1 S01E04 Emancipation.mkv
Stargate SG-1 S01E05 The Broca Divide.mkv
Stargate SG-1 S01E06 The First Commandment.mkv
Stargate SG-1 S01E07 Cold Lazarus.mkv
Stargate SG-1 S01E08 The Nox.mkv
Stargate SG-1 S01E09 Brief Candle.mkv
Stargate SG-1 S01E10 Thor's Hammer.mkv
Stargate SG-1 S01E11 The Torment of Tantalus.mkv
Stargate SG-1 S01E12 Bloodlines.mkv
Stargate SG-1 S01E13 Fire and Water.mkv
Stargate SG-1 S01E14 Hathor.mkv
Stargate SG-1 S01E15 Singularity.mkv
Stargate SG-1 S01E16 Cor-Ai.mkv
Stargate SG-1 S01E17 Enigma.mkv
Stargate SG-1 S01E18 Solitudes.mkv
Stargate SG-1 S01E19 Tin Man.mkv
Stargate SG-1 S01E20 There But For the Grace of God.mkv
Stargate SG-1 S01E21 Politics (1).mkv
Stargate SG-1 S01E22 Within the Serpent's Grasp (2).mkv
";
// 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/