// 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"\s*([^:\n]+):\s*((?:(?!: |\n)[\s\S])*)(?=\s+[^:\n]+:|$)").unwrap();
let string = "System: Host: ict-vm Kernel: 4.4.0-53-generic i686 (32 bit)
Desktop: MATE 1.16.1 Distro: Linux Mint 18.1 Serena
Machine: System: ASUSTeK (portable) product: N43SN v: 1.0
Mobo: ASUSTeK model: N43SN v: 1.0 serial: NB-1234567890
Bios: American Megatrends v: N43SN.412 date: 09/21/2011
CPU: Quad core Intel Core i7-2670QM (-HT-MCP-) cache: 6144 KB
clock speeds: max: 3100 MHz 1: 807 MHz 2: 814 MHz 3: 800 MHz
4: 1078 MHz 5: 990 MHz 6: 811 MHz 7: 801 MHz 8: 844 MHz
Graphics: Card-1: Intel 2nd Generation Core Processor Family Integrated Graphics Controller
Card-2: NVIDIA GF108M [GeForce GT 550M]
Display Server: X.org 1.18.4 drivers: intel (unloaded: fbdev,vesa) FAILED: nouveau
tty size: 80x24 Advanced Data: N/A for root
Audio: Card Intel 6 Series/C200 Series Family High Definition Audio Controller
driver: snd_hda_intel
Sound: Advanced Linux Sound Architecture v: k4.4.0-53-generic
Network: Card-1: Qualcomm Atheros AR9285 Wireless Network Adapter (PCI-Express)
driver: ath9k
IF: wlp3s0 state: up mac: 7x:2t:61:d4:72:8a
Card-2: Qualcomm Atheros AR8151 v2.0 Gigabit Ethernet driver: atl1c
IF: enp4s0 state: down mac: 14:da:e1:ay:72:b5
Drives: HDD Total Size: 507.9GB (0.4% used)
ID-1: /dev/sda model: ST95005620AS size: 500.1GB
ID-2: USB /dev/sdb model: DataTraveler_3.0 size: 7.8GB
RAID: No RAID devices: /proc/mdstat, md_mod kernel module present
Sensors: System Temperatures: cpu: 48.0C mobo: N/A gpu: 43.0
Fan Speeds (in rpm): cpu: N/A
Info: Processes: 223 Uptime: 40 min Memory: 531.1/3948.3MB
Client: Shell (sudo) inxi: 2.2.35 System: Host: ict-vm Kernel: 4.4.0-53-generic i686 (32 bit)
Desktop: MATE 1.16.1 Distro: Linux Mint 18.1 Serena
Machine: System: ASUSTeK (portable) product: N43SN v: 1.0
Mobo: ASUSTeK model: N43SN v: 1.0 serial: NB-1234567890
Bios: American Megatrends v: N43SN.412 date: 09/21/2011
CPU: Quad core Intel Core i7-2670QM (-HT-MCP-) cache: 6144 KB
clock speeds: max: 3100 MHz 1: 807 MHz 2: 814 MHz 3: 800 MHz
4: 1078 MHz 5: 990 MHz 6: 811 MHz 7: 801 MHz 8: 844 MHz
Graphics: Card-1: Intel 2nd Generation Core Processor Family Integrated Graphics Controller
Card-2: NVIDIA GF108M [GeForce GT 550M]
Display Server: X.org 1.18.4 drivers: intel (unloaded: fbdev,vesa) FAILED: nouveau
tty size: 80x24 Advanced Data: N/A for root
Audio: Card Intel 6 Series/C200 Series Family High Definition Audio Controller
driver: snd_hda_intel
Sound: Advanced Linux Sound Architecture v: k4.4.0-53-generic
Network: Card-1: Qualcomm Atheros AR9285 Wireless Network Adapter (PCI-Express)
driver: ath9k
IF: wlp3s0 state: up mac: 7x:2t:61:d4:72:8a
Card-2: Qualcomm Atheros AR8151 v2.0 Gigabit Ethernet driver: atl1c
IF: enp4s0 state: down mac: 14:da:e1:ay:72:b5
Drives: HDD Total Size: 507.9GB (0.4% used)
ID-1: /dev/sda model: ST95005620AS size: 500.1GB
ID-2: USB /dev/sdb model: DataTraveler_3.0 size: 7.8GB
RAID: No RAID devices: /proc/mdstat, md_mod kernel module present
Sensors: System Temperatures: cpu: 48.0C mobo: N/A gpu: 43.0
Fan Speeds (in rpm): cpu: N/A
Info: Processes: 223 Uptime: 40 min Memory: 531.1/3948.3MB
Client: Shell (sudo) inxi: 2.2.35";
// 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/