// 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)^(?=.*\bDATA1="(?<d1>[^"]+)"\h*)?(?=.*\bDATA2="(?<d2>[^"]+)"\h*)?(?=.*\bDATA3="(?<d3>[^"]+)"\h*)?(?=.*\bDATA4="(?<d4>[^"]+)"\h*)?(?=.*\bDATA5="(?<d5>[^"]+)"\h*)?.*"#).unwrap();
let string = "DATA1=\"8DE\" DATA2=\"322\" DATA3=\"20\" DATA4=\"19.99\" DATA5=\"0.01\"
DATA1=\"FE4\" DATA2=\"222\" DATA4=\"400\" DATA3=\"400\" DATA5=\"0.00\"
DATA1=\"CE3\" DATA2=\"444\" DATA4=\"60\" DATA5=\"0.00\" DATA3=\"60\"
DATA1=\"MME\" DATA3=\"20\" DATA4=\"20\" DATA5=\"0.00\"
DATA2=\"667\" DATA4=\"30\" DATA3=\"30\" DATA5=\"0.00\" DATA1=\"MH4\"";
let substitution = "${d1}\\t\\t${d2}\\t\\t${d3}\\t\\t${d4}\\t\\t${d5}";
// 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/