// 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"(?mx)[[:blank:]]*+(?:[\[\(].*[\]\)][[:blank:]]*+)?(.*?)[[:blank:]\[\(]*+([1-2]\d{3}).*
").unwrap();
let string = "2 Fast 2 Furious [2003] [SD]
2 Fast 2 Furious (2003) [SD]
2 Fast 2 Furious ((2003) [SD]
A Goofy Movie (1995) (HD) (720p)
[test]A Goofy Movie (1995) (HD) (720p)
(test) A Goofy Movie (1995) (HD) (720p)
2 Fast 2 Furious 2003
2 Fast 2 Furious 2003
The Lion King 2- Simba's Pride (1998) (HD) (1080p)
The.Grand.Budapest.Hotel.2014.1080p.BluRay.x264-BLOW
Another.Earth.2011.LIMITED.720p.BluRay.X264-AMIABLE
The.Green.Mile.1999.720p.BluRay.x264-HDCLASSiCS
The Road 2009 Bluray DTS 720 p - TRiNiTY
Dead Poets Society (1989) 720p Blu-ray x264 DTS MSubs [DDR]
Garden.State.2004.720p.BluRay.X264-AMIABLE
";
let substitution = "\\1 (\\2) \\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/