// 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)^[ \t]*([0]|([-+]?(\d*\.)?\d+)(cm|mm|in|px|pt|pc|Q|em|ex|ch|rem|vw|vh|vmin|vmax|%)){1}([\t ]+([0]|([-+]?(\d*\.)?\d+)(cm|mm|in|px|pt|pc|Q|em|ex|ch|rem|vw|vh|vmin|vmax|%))){0,3}[\t ]*$").unwrap();
let string = "0
0
0px
0px 0px 0px 0
0 0
0cm 0px 0ch 0%
0 0
0 0 0
0 0 0
0 0 0 0
2px 0
+2px
-3px
0 2px
3cm
0px
0px 0px 0px
1px
2px 2px
3px 3px 3px
4px 4px 4px 4px
+4px -4px -4px +4px
-1px
-2px -2px
-3px -3px -3px
-4px -4px -4px -4px
1%
2% 2vh
3vw 3vh 3%
4cm 4pt -4vmin 4vmax
# Errors - must not match
00
0 0px 00
1px-2px
2px2px
3pxf 3px 3px sdsd
4px-4px 4px 4px
4px4px4px4px
4px 4px 4px 4-px
-4px-4px-4px-4px
--3px
+-3px
-4px-4px -4px- 4px
-4
+5
+0px -0
+0";
// 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/