// 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"weapon(?:(?:_[^\W_]+)+(?=_[^\W_]{2}_)|(?:(?!_[^\W_]{2}_)_[^\W_]+)+)").unwrap();
let string = "econ/default_generated/weapon_knife_flip_so_night_medium
econ/default_generated/weapon_bayonet_hy_ocean_knife_medium
econ/default_generated/weapon_knife_gut_aq_blued_heavy
econ/default_generated/weapon_knife_karambit_hy_webs_medium
econ/default_generated/weapon_knife_m9_bayonet_so_night_lightasd
econ/default_generated/weapon_knife_tactical_hy_ddpat_light
econ/default_generated/weapon_knife_falchion_aa_fade_heavy
econ/default_generated/weapon_knife_survival_bowie_am_doppler_phase3_heavy
econ/default_generated/weapon_knife_butterfly_hy_ddpat_medium
econ/default_generated/weapon_knife_push_hy_ddpat_light";
// result will be an iterator over tuples containing the start and end indices for each match in the string
let result = regex.captures_iter(string);
for mat in result {
println!("{:?}", mat);
}
}
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/