// 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)pam\.username%([A-Za-z0-9]+)@|\s\(([0-9]+)\)").unwrap();
let string = "Sep 11 03:02:00 (1568505720.145620) danted[10402]: info: pass(2): tcp/connect -: pam.username%MyUsername@46.111.111.250.48198 123.12.12.112.1080 -> 123.12.12.112.48198 111.123.123.147.443 (319721)
Sep 11 03:02:00 (1568505720.147471) danted[10402]: info: pass(2): tcp/connect -: pam.username%MyUsername@46.111.111.250.37449 123.12.12.112.1080 -> 123.12.12.112.37449 123.123.123.211.443 (312)
Sep 11 03:02:00 (1568505720.148240) danted[10402]: info: pass(2): tcp/connect -: 111.123.123.147.443 123.12.12.112.48198 -> 123.12.12.112.1080 pam.username%MyUsername@46.111.111.250.48198 (723)
Sep 11 03:02:00 (1568505720.154784) danted[10402]: info: pass(2): tcp/connect -: 123.123.123.211.443 123.12.12.112.37449 -> 123.12.12.112.1080 pam.username%MyUsername@46.111.111.250.37449 (8831)";
let substitution = "";
// result will be a String with the substituted value
let result = regex.replace_all(string, substitution);
println!("{}", result);
}
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/