// 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#"(NAME)((\s)?:(\s)?)([ |,| (|)|\\|\.|\"|\w|\-|\+]*)((\s)*?,(\s)*?)(DESCR)((\s)?:(\s)?)([ |,| (|)|\\|\.|\"|\w|\-|\+]*)(\s)"#).unwrap();
let string = "WDL3-4N-C4510-1A#show inventory
NAME: \"Switch System\", DESCR: \"Cisco Systems, Inc. WS-C4510R+E 10 slot switch \"
PID: WS-C4510R+E , VID: V03 , SN: FOX1616GNS8
NAME: \"Clock Module\", DESCR: \"Clock Module\"
PID: WS-X4K-CLOCK-E , VID: V01 , SN: NWG161794PT
NAME: \"Mux Buffer 1 \", DESCR: \"Mux Buffers for Redundancy Logic\"
PID: WS-X4590-EX= , VID: , SN: NWG16179CP9
NAME: \"Mux Buffer 2 \", DESCR: \"Mux Buffers for Redundancy Logic\"
PID: WS-X4590-EX= , VID: , SN: NWG16179C3T
NAME: \"Mux Buffer 3 \", DESCR: \"Mux Buffers for Redundancy Logic\"
PID: WS-X4590-EX= , VID: , SN: NWG16179CUN
NAME: \"Mux Buffer 4 \", DESCR: \"Mux Buffers for Redundancy Logic\"
PID: WS-X4590-EX= , VID: , SN: NWG16179AXZ
NAME: \"Mux Buffer 7 \", DESCR: \"Mux Buffers for Redundancy Logic\"
PID: WS-X4590-EX= , VID: , SN: NWG16179CTE
NAME: \"Mux Buffer 8 \", DESCR: \"Mux Buffers for Redundancy Logic\"
PID: WS-X4590-EX= , VID: , SN: NWG16179C3V
NAME: \"Mux Buffer 9 \", DESCR: \"Mux Buffers for Redundancy Logic\"
PID: WS-X4590-EX= , VID: , SN: NWG16179CLW
NAME: \"Mux Buffer 10 \", DESCR: \"Mux Buffers for Redundancy Logic\"
PID: WS-X4590-EX= , VID: , SN: NWG16179CVU
NAME: \"Linecard(slot 1)\", DESCR: \"10/100/1000BaseT (RJ45)+V E Series with 48 10/100/1000 baseT Premium PoE ports (Cisco/IEEE)\"
PID: WS-X4748-RJ45V+E , VID: V03 , SN: CAT1624L2J7
";
// 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/