// 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)(?:\s*?NAME\s*?:\s*?\"?)([0-9A-Za-z- ,]+)(?:\"?\s*?,\s*?)(?:DESCR\s*?:\s*\"?)([0-9A-Za-z- ,/+:]+)(?:\"?\s*?PID\s*?:\s*?)([0-9A-Z-]+)(?:\s*?,\s*?VID\s*?:\s*?)([0-9A-Z/]+)(?:\s*?,\s*?SN\s*?:\s*?)([0-9A-Z/]+)"#).unwrap();
let string = "NAME: \"Chassis\", DESCR: \"Nexus C9348GC-FXP chassis\"
PID: N9K-C9348GC-FXP , VID: V01 , SN: FFFFFFFFFFF
NAME: \"Slot 1 \", DESCR: \"48x100M/1G \"
PID: N9K-C9348GC-FXP , VID: V01 , SN: FFFFFFFFFFF
NAME: \"GEM \", DESCR: \"4x25G+2x100G Switch \"
PID: N9K-C9348GC-FXP , VID: V01 , SN: FFFFFFFFFFF
NAME: \"power Supply 1\", DESCR: \"PSU \"
PID: NXA-PAC-350W-PE , VID: V01 , SN: DDDDDDDDDDD
NAME: \"power Supply 2\", DESCR: \"PSU \"
PID: NXA-PAC-350W-PE , VID: V01 , SN: DDDDDDDDDDD
NAME: \"Fan 1 \", DESCR: \"fan \"
PID: NXA-FAN-30CFM-F , VID: N/A , SN: N/A
NAME: \"Fan 2 \", DESCR: \"fan \"
PID: NXA-FAN-30CFM-F , VID: N/A , SN: N/A
NAME: \"Fan 3 \", DESCR: \"fan \"
PID: NXA-FAN-30CFM-F , VID: N/A , SN: N/A";
let substitution = "";
// 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/