// 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)((?:bs )?(?:en )?(?:np )?(?:is[o0]|DIN)\s+[-\d]+:)(.+:)?(\d{4}(?:\(\w\))?)").unwrap();
let string = "ISO 11784:1996/Amd.2:2010(E)
ISO 11784:2010(E)
ISO 11784:2010
ISO 11784-2-3-4:1996/Amd.2:2010(E)
ISO 11784-2-8-7:2010(E)
ISO 11784-5-120-78949-56-789:2010
BS EN ISO 11784:1996/Amd.2:2010(E)
EN ISO 11784:2010(E)
IS0 11784:2010
EN NP IS0 11784-2-3-4:1996/Amd.2:2010(E)
BS IS0 11784-2-8-7:2010(E)
EN NP ISO 11784-5-120-78949-56-789:2010
EN DIN 11784-5:2019(B)";
let substitution = "$1$3";
// 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/