// 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)^(?!.*\-{2}.*)(?!.*\+{2}.*)(?!.*\.{2}.*)(?P<major>(?!0)(\d*)|([0[^\d]))((?>\.)(?P<minor>\g<1>))\.(?P<patch>\g<minor>)(?![\+\-][^a-zA-Z0-9])(\g<2>(\-(?P<release>[a-zA-Z0-9\.-]+)))?(\+(?P<build>\g<9>))?$").unwrap();
let string = "#good
0.1.2
1.2.3
10.20.3
1.2.3-alpha.23-pre
12.12.3-123.hexagon+dontmakemecompileplea.se
1.2.3-alpha-dev.51-something+mybuild-1-4-1975-clang
4.3.22+mybuild
4.1.405+hexa.13331-objectfiles
# bad
01.2.3
1.02.3
2.3.04
a.1.1
1.a.1
1.1.a
1.2.3-rele..ase+build
1.2.3-release-something+..build
1.2.3-rele--ase+build
1.2.3-release-something+--build
1.2.3-release++build
1.2.3+-release-something-build";
// 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/