// 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"\[((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))\]").unwrap();
let string = "Nov 16 14:21:05 192.168.77.20/192.168.77.167 1 2016-11-16T14:21:05+08:00 s_sys@aaa1 snmptrapd 19644 - - '14:21:5 16/11/2016 UDP: [10.80.0.254]:58919 wcore Cold Start sysUpTimeInstance = 24:16:28:17.07 snmpTrapOID.0 = cmnMacMoveNotification cmnMACMoveAddress.0 = e0:66:78:8a:93:bb cmnMACMoveVlanNumber.0 = 30 cmnMACMoveFromPortId.0 = 1669 cmnMACMoveToPortId.0 = 1668 cmnMACMoveTime.0 = 24:16:28:17.07'";
// 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/