// 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)^\w+\s+\d+\s+\d{2}(?::\d{2}){2}\s+(?P<devicename1>\S+)").unwrap();
let string = "Nov 1 00:00:21 akdcs20.ftc.abcd-ipsn AKDCS20 fpc0 LBCM-L2,brcm_port_learning_config(),1258:(brcm_port_learning_config:1258) Setting L2 learning unit:0,port_num:44, learn_flg 5
Nov 1 01:27:16 spnztpm01.abcd-ipsn 553177: LC/0/0/CPU0:Nov 1 01:27:16.040 : ifmgr[200]: %PKT_INFRA-LINEPROTO-5-UPDOWN : Line protocol on Interface TenGigE0/0/0/1.172153, changed state to Up
Oct 31 23:59:56 akdcs19.ftc.abcd-ipsn AKDCS19 ufdd[1679]: ufd_group_config_if_lookup ifname ae4 ";
// 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/