// 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)^\/ignition-interlock-device\/([a-z]*?)\/(locations)?\/smart-start-of-([a-z0-9-]*?)(\/)?$").unwrap();
let string = "/ignition-interlock-device/colorado/locations/smart-start-of-alamosa/
/ignition-interlock-device/colorado/locations/smart-start-of-auburn-2/
/ignition-interlock-device/florida/locations/smart-start-of-beverly/
/ignition-interlock-device/florida/locations/smart-start-of-boca-raton-2/
/ignition-interlock-device/florida/locations/smart-start-of-brownsville/
/ignition-interlock-device/florida/locations/smart-start-of-camrose/
/ignition-interlock-device/florida/locations/smart-start-of-carbondale/
/ignition-interlock-device/florida/locations/smart-start-of-carson-city/
/ignition-interlock-device/florida/locations/smart-start-of-centereach/
/ignition-interlock-device/florida/locations/smart-start-of-charleston-2/
/ignition-interlock-device/florida/locations/smart-start-of-charleston/
/ignition-interlock-device/florida/locations/smart-start-of-danielson/
/ignition-interlock-device/florida/locations/smart-start-of-defuniak-springs/
/ignition-interlock-device/florida/locations/smart-start-of-deland-2/
/ignition-interlock-device/florida/locations/smart-start-of-durango/
/ignition-interlock-device/florida/locations/smart-start-of-farmington/
/ignition-interlock-device/florida/locations/smart-start-of-framingham/
/ignition-interlock-device/florida/locations/smart-start-of-gallatin/
/ignition-interlock-device/florida/locations/smart-start-of-gresham/
/ignition-interlock-device/florida/locations/smart-start-of-gypsum/
/ignition-interlock-device/florida/locations/smart-start-of-hialeah/
/ignition-interlock-device/florida/locations/smart-start-of-holly-hill-2/
/ignition-interlock-device/florida/locations/smart-start-of-honolulu-3/
/ignition-interlock-device/florida/locations/smart-start-of-huntington/
/ignition-interlock-device/florida/locations/smart-start-of-huntsville/
/ignition-interlock-device/florida/locations/smart-start-of-kennesaw/
/ignition-interlock-device/florida/locations/smart-start-of-kennewick/
/ignition-interlock-device/florida/locations/smart-start-of-kissimmee-2/
/ignition-interlock-device/florida/locations/smart-start-of-la-crosse/
/ignition-interlock-device/florida/locations/smart-start-of-laramie/
/ignition-interlock-device/florida/locations/smart-start-of-lawton/
/ignition-interlock-device/florida/locations/smart-start-of-longwood/
/ignition-interlock-device/florida/locations/smart-start-of-malden/
/ignition-interlock-device/florida/locations/smart-start-of-mckinney/
/ignition-interlock-device/florida/locations/smart-start-of-medford/
/ignition-interlock-device/florida/locations/smart-start-of-middletown-2/
/ignition-interlock-device/florida/locations/smart-start-of-middletown/
/ignition-interlock-device/florida/locations/smart-start-of-mildura/
/ignition-interlock-device/florida/locations/smart-start-of-new-port-richey/
/ignition-interlock-device/florida/locations/smart-start-of-norco/
/ignition-interlock-device/florida/locations/smart-start-of-ocala-2/
/ignition-interlock-device/florida/locations/smart-start-of-palm-bay-2/
/ignition-interlock-device/florida/locations/smart-start-of-palm-bay/
/ignition-interlock-device/florida/locations/smart-start-of-panama-city-2/
/ignition-interlock-device/florida/locations/smart-start-of-port-charlotte-2/
/ignition-interlock-device/florida/locations/smart-start-of-richmond-3/
/ignition-interlock-device/florida/locations/smart-start-of-saint-paul-2/
/ignition-interlock-device/florida/locations/smart-start-of-san-marcos/
/ignition-interlock-device/florida/locations/smart-start-of-santa-ana/
/ignition-interlock-device/florida/locations/smart-start-of-show-low/
/ignition-interlock-device/florida/locations/smart-start-of-staunton/
/ignition-interlock-device/florida/locations/smart-start-of-tallahassee-2/
/ignition-interlock-device/florida/locations/smart-start-of-titusville/
/ignition-interlock-device/florida/locations/smart-start-of-uppsala-2/
/ignition-interlock-device/florida/locations/smart-start-of-van-wert/
/ignition-interlock-device/florida/locations/smart-start-of-west-monroe/
/ignition-interlock-device/florida/locations/smart-start-of-west-palm-beach-2/";
let substitution = "/locations/?location_redirect=$3&state=$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/