// 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)(?<=sda1)\s+(?|(\d+.?\d+)[G,M.L,%]?)\s+(?|(\d+.?\d+)[G,M.L,%]?)\s+(?|(\d+.?\d+)[G,M.L,%]?)\s+(\d+)%").unwrap();
let string = "Filesystem Size Used Avail Use% Mounted on
udev 3.8G 0 3.8G 0% /dev
tmpfs 806M 5.3M 800M 1% /run
/dev/mmcblk0p2 235G 59G 164G 27% /
tmpfs 4.0G 0 4.0G 0% /dev/shm
tmpfs 5.0M 48K 5.0M 1% /run/lock
/dev/mmcblk0p1 510M 63M 448M 13% /boot/firmware
/dev/sda1 137.8G 299.88G 127G 3% /media/usbplatte
tmpfs 806M 0 806M 0% /run/user/1000
/dev/sda1 139752 2662 129920 3% /media/usbplatte
";
// 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/