// 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"(?<action>[a-zA-Z]+)@\/(?<dev_path>.*)\/(?<subsystem>[a-zA-z]+)\/(?<name>[a-zA-z]+)").unwrap();
let string = "change@/devices/soc/9000000.usb/power_supply/usb
change@/devices/soc/9000000.usb/power_supply/usb
change@/devices/virtual/android_usb/android0
change@/devices/soc/99999999.i2c/i2c-3/3-0025/power_supply/battery
change@/devices/soc/9000000.usb/power_supply/usb
change@/devices/soc/9000000.usb/power_supply/usb
change@/devices/soc/soc:usb_charger/power_supply/usb_charger
change@/devices/soc/soc:mains_charger/power_supply/mains_charger
change@/devices/soc/99999999.i2c/i2c-3/3-0025/power_supply/battery
change@/devices/soc/99999999.i2c/i2c-3/3-0025/power_supply/battery
change@/devices/soc/99999999.i2c/i2c-3/3-0025/power_supply/battery
change@/devices/soc/soc:usb_charger/power_supply/usb_charger
change@/devices/soc/soc:mains_charger/power_supply/mains_charger
change@/devices/soc/99999999.i2c/i2c-3/3-0025/power_supply/battery
";
// 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/