// 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)^(?<major>0|[1-9]\d*)\.(?<minor>0|[1-9]\d*)\.(?<patch>0|[1-9]\d*)(?:-(?<preRelease>(?:[a-zA-Z1-9][a-zA-Z\d]*|0\d*[a-zA-Z][a-zA-Z\d]*|0)(?:\.(?:[a-zA-Z1-9][a-zA-Z\d]*|0\d*[a-zA-Z][a-zA-Z\d]*|0))*))?(?:\+(?<metadata>(?:[a-zA-Z\d-]*)(?:\.(?:[a-zA-Z\d-]*))*))?$").unwrap();
let string = "0.1.0
01.2.1
1.2.0
1.0.0
1.01.0
1.0.01
1.0.0-0df34.ahgdfhsdf.0005a56tg
1.0.0-0054.df4gf
1.0.0-005a4.df4gf
1.0.0-005a4.df4gf+adffbff.sdfg.sdfg.adf78df7d8df7
1.0.0-005a4.df4gf+adffbff.sdfg.sdfg.00000000.dfsg.sdf-sfg.sdfg-sdfg.sgf
900.10.85494
0900.10.54";
// 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/