// 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"(?<src_ip>\d{0,2}\.\d{0,2}\.\d{0,2}\.\d{0,2})\s(?<signture>%(?<product>ASA))-(?<version>(?<release>\d+)-(?<build>\d+)):").unwrap();
let string = "May 9 14:30:00 10.25.8.3 %ASA-6-302013: Built outbound TCP connection 1032748840 for MGM-CML-NON-LB-SRV-Log:10.25.3.21/9997 (10.25.3.21/9997) to MIT-IBMgmt-NW:10.70.21.165/4379 (10.70.21.165/4379)";
// 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/