// 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),"(?<date>\d\d\d\d-\d\d-\d\d)\ (?<time>\d\d:\d\d:\d\d).*\[(?<jail>sshd|recidive|mysqld-auth)\]\ (?<action>[a-zA-z]*)\ (?<ip_address>[\d\.]*)"#).unwrap();
let string = "@timestamp,@message
2021-04-30 18:17:08.504,\"2021-04-30 19:17:04,189 fail2ban.filter [100432]: INFO [sshd] Found 221.181.185.223 - 2021-04-30 19:17:03\"
2021-04-30 18:11:24.504,\"2021-04-30 19:11:20,137 fail2ban.filter [100432]: INFO [sshd] Found 221.181.185.198 - 2021-04-30 19:11:19\"
2021-04-30 18:04:24.504,\"2021-04-30 19:04:19,434 fail2ban.filter [100432]: INFO [sshd] Found 221.131.165.56 - 2021-04-30 19:04:19\"
2021-04-30 18:03:04.504,\"2021-04-30 19:02:59,705 fail2ban.filter [100432]: INFO [sshd] Found 213.171.212.141 - 2021-04-30 19:02:59\"
2021-04-30 17:58:11.504,\"2021-04-30 18:58:06,901 fail2ban.filter [100432]: INFO [recidive] Found 205.185.119.236 - 2021-04-30 18:58:06\"
2021-04-30 17:58:07.132,\"2021-04-30 18:58:06,628 fail2ban.actions [100432]: NOTICE [sshd] Ban 205.185.119.236\"
2021-04-30 17:58:06.631,\"2021-04-30 18:58:06,208 fail2ban.filter [100432]: INFO [sshd] Found 205.185.119.236 - 2021-04-30 18:58:05\"
2021-04-30 17:58:06.381,\"2021-04-30 18:58:06,206 fail2ban.filter [100432]: INFO [sshd] Found 205.185.119.236 - 2021-04-30 18:58:05\"
2021-04-30 17:58:06.381,\"2021-04-30 18:58:06,206 fail2ban.filter [100432]: INFO [sshd] Found 205.185.119.236 - 2021-04-30 18:58:05\"
2021-04-30 17:58:06.381,\"2021-04-30 18:58:06,207 fail2ban.filter [100432]: INFO [sshd] Found 205.185.119.236 - 2021-04-30 18:58:05\"
2021-04-30 17:58:06.381,\"2021-04-30 18:58:06,207 fail2ban.filter [100432]: INFO [sshd] Found 205.185.119.236 - 2021-04-30 18:58:05\"
2021-04-30 17:58:06.380,\"2021-04-30 18:58:06,205 fail2ban.filter [100432]: INFO [sshd] Found 205.185.119.236 - 2021-04-30 18:58:05\"
2021-04-30 17:57:40.504,\"2021-04-30 18:57:35,482 fail2ban.filter [100432]: INFO [sshd] Found 221.181.185.143 - 2021-04-30 18:57:35\"
2021-04-30 17:41:27.504,\"2021-04-30 18:41:23,069 fail2ban.filter [100432]: INFO [sshd] Found 221.181.185.135 - 2021-04-30 18:41:22\"
2021-04-30 17:40:09.504,\"2021-04-30 18:40:05,206 fail2ban.filter [100432]: INFO [sshd] Found 222.187.239.107 - 2021-04-30 18:40:04\"
2021-04-30 17:38:16.504,\"2021-04-30 18:38:11,847 fail2ban.filter [100432]: INFO [sshd] Found 221.181.185.151 - 2021-04-30 18:38:11\"";
// 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/