// 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)(X(-?\d+(?:\.\d+)?))?\s*(Y(-?\d+(?:\.\d+)?))?").unwrap();
let string = "N14 X411 Y279.05
N15 G2 X33 Y280.4 I.001 J4.00
N16 G1 X408 Y280.4
N17 G2 X402.3 Y280.09 I-3 J2.65
N18 G1 X402.3 Y280.09
N19 G2 X402.09 Y285.79 I2.7 J2.95
N20 G1 X402.09 Y285.79
N3 G40 Y6000
N3 G40 X-6000";
// 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/