// 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#"KNAME=\"(.*)\" FSTYPE=\"(.*)\" SIZE=\"(.*)\" MOUNTPOINT=\"(.)*\" LABEL=\"(.*)\" MODEL=\"(.*)\""#).unwrap();
let string = "# lsblk -d -P -o KNAME,FSTYPE,SIZE,MOUNTPOINT,LABEL,MODEL
KNAME=\"sda\" FSTYPE=\"\" SIZE=\"80G\" MOUNTPOINT=\"\" LABEL=\"\" MODEL=\"VBOX HARDDISK \"
KNAME=\"sda1\" FSTYPE=\"\" SIZE=\"243M\" MOUNTPOINT=\"/boot\" LABEL=\"\" MODEL=\"\"
KNAME=\"sda2\" FSTYPE=\"\" SIZE=\"1K\" MOUNTPOINT=\"\" LABEL=\"\" MODEL=\"\"
KNAME=\"sda5\" FSTYPE=\"\" SIZE=\"79.8G\" MOUNTPOINT=\"\" LABEL=\"\" MODEL=\"\"
KNAME=\"dm-0\" FSTYPE=\"\" SIZE=\"79G\" MOUNTPOINT=\"/\" LABEL=\"\" MODEL=\"\"
KNAME=\"dm-1\" FSTYPE=\"\" SIZE=\"768M\" MOUNTPOINT=\"[SWAP]\" LABEL=\"\" MODEL=\"\"
KNAME=\"sr0\" FSTYPE=\"\" SIZE=\"1024M\" MOUNTPOINT=\"\" LABEL=\"\" MODEL=\"CD-ROM \"
KNAME=\"sr1\" FSTYPE=\"\" SIZE=\"1024M\" MOUNTPOINT=\"\" LABEL=\"\" MODEL=\"CD-ROM \"";
// 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/