// 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"Representatives:\s+(?<rep_name>.*)\(.*\)\s+((?<rep2_name>.*)?\s+\()?").unwrap();
let string = "----------------------------------------------
SESSION SUMMARY
----------------------------------------------
Representatives:
Amoz Abraham (ID: 23)
Jose Sandoval (ID: 25)
Customer Name: [Pinned] SOUTHLAWN02
Customer's Public IP: 174.110.83.140:56969
Customer's Private IP: 10.5.65.90
Session Start Time: 2020-05-15 17:03:22 US/Pacific
Session End Time: 2020-05-15 17:11:37 US/Pacific
Duration: 00:08:15
# Files Transferred: 0
# Files Moved: 0
# Files Deleted: 0
----------------------------------------------
SYSTEM INFORMATION RETRIEVED
----------------------------------------------
## General ##
Version: Windows 10 Pro x64
Computer Name: SOUTHLAWN02
System BIOS:
Processor 1 Info: Intel(R) Core(TM) i5-9500 CPU @ 3.00GHz
Processor 2 Info: Intel(R) Core(TM) i5-9500 CPU @ 3.00GHz
Processor 3 Info: Intel(R) Core(TM) i5-9500 CPU @ 3.00GHz
Processor 4 Info: Intel(R) Core(TM) i5-9500 CPU @ 3.00GHz
Processor 5 Info: Intel(R) Core(TM) i5-9500 CPU @ 3.00GHz
Processor 6 Info: Intel(R) Core(TM) i5-9500 CPU @ 3.00GHz
Default Browser: Google Chrome
Default Browser Version: 81.0.4044.138
Default Browser Location: C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe
Windows® Directory: C:\\Windows
System Directory: C:\\Windows\\system32
Time Zone: Eastern Daylight Time
";
// result will be a tuple containing the start and end indices for the first match in the string
let result = regex.captures(string);
let (start, end) = match result {
Some((s, e)) => (s, e),
None => {
// ...
}
};
println!("{}", &string[start, end]);
}
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/