// 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"(?im)(,\s(?:vol|pt)\.(*SKIP)(*F)|(?:vol|pt|volume|part))").unwrap();
let string = "Should Match:
a) Any occurences of \"Volume\" OR \"Part\" (Case Insensitive);
b) Any occurence of \"vol\" or \"pt\" (CI) that does not have [[comma][space] before AND [period] after;
My volume 1
My name vol2.
My, volume 1
, pt. vol2.
, part.
, pt.
, pt
, vol
. pt.
// Should match below as there is no [period] after it
The Red Pill, Pt 2
, Pt 2";
let substitution = "\\1";
// 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/