// 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"(?mx)^\h*
(?<linetype>[0123456])\h+
(?<color> (?&Number) )\h+
(?<xrot> (?&Number) )\h+ (?<yrot> (?&Number) )\h+ (?<zrot> (?&Number) )\h+
(?<xpos> (?&Number) )\h+ (?<ypos> (?&Number) )\h+ (?<zpos> (?&Number) )\h+
(?<xcam> (?&Number) )\h+ (?<ycam> (?&Number) )\h+ (?<zcam> (?&Number) )\h+
(?<xsca> (?&Number) )\h+ (?<ysca> (?&Number) )\h+ (?<zsca> (?&Number) )\h+
(?<filename>\S+[.]\S+)
$
(?(DEFINE)
(?<Number> [-]? \d+ (?> [.]\d* )? (?> [Ee] [+-]? \d+ )? )
)").unwrap();
let string = "1 0 0 0 0 1 0 0 0 1 0 0 0 1 3024.dat
#linetype color XROT YROY ZROT XPOS YPOS ZPOS XCAM YCAM ZCAM XSCA YSCA ZSCA FILE";
let substitution = "${linetype} ${color} ($xrot,$yrot,$zrot) {$xpos,$ypos,$zpos} <$xcam,$ycam,$zcam> [$xsca,$ysca,$zsca] \"$filename\"";
// result will be a String with the substituted value
let result = regex.replace_all(string, substitution);
println!("{}", result);
}
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/