// 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|$]").unwrap();
let string = "/var/log/audit/audit.log
/var/log/audit/audit.log.1
/var/log/boot.log
/var/log/btmp
/var/log/btmp-20170401
/var/log/chrony
/var/log/cron
/var/log/cron-20170326
/var/log/cron-20170402
/var/log/cron-20170410
/var/log/cron-20170416
/var/log/anaconda
./var/log/anaconda/anaconda.log
./var/log/anaconda/ifcfg.log
./var/log/anaconda/journal.log
./var/log/anaconda/ks-script-XcavhD.log
./var/log/anaconda/packaging.log
./var/log/anaconda/program.log
./var/log/anaconda/storage.log
./var/log/anaconda/syslog
./var/log/anaconda/X.log
./var/log/audit
./var/log/audit/audit.log
./var/log/audit/audit.log.1
/var/log/httpd/error_log;
";
// 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/