// 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)(^reflectance_\d_)(\S*)$").unwrap();
let string = "reflectance_7_myd21a1_emissivity_29
reflectance_7_myd21a1_emissivity_29_savitzkygolay
reflectance_7_myd21a1_emissivity_31
reflectance_7_myd21a1_emissivity_31_savitzkygolay
reflectance_3_myd21a1_emissivity_32
reflectance_2_myd21a1_emissivity_32_savitzkygolay
reflectance_1_mcd43a3_albedo_bsa_band1
reflectance_3_mcd43a3_albedo_bsa_band2
reflectance_7_mcd43a3_albedo_bsa_nir
reflectance_7_mcd43a3_albedo_bsa_shortwave
reflectance_7_mcd43a3_albedo_bsa_vis
reflectance_7_mcd43a3_albedo_wsa_band1
reflectance_7_mcd43a3_albedo_wsa_band2
reflectance_7_mcd43a3_albedo_wsa_nir
reflectance_7_mcd43a3_albedo_wsa_shortwave
reflectance_7_mcd43a3_albedo_wsa_vis";
let substitution = "($1)vs_$2";
// 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/