// 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)\[(?<prefix>.*:)?\s*(?<expr>((?<left>.*?)\s*(@|[Dd][Cc])\s*(?<test>(?<right>.*?)\]))|(?<data>.*)\]\s*(?=\())\s*(\((?<fail>(.*?))\/(?<pass>.*?)\))?").unwrap();
let string = "[Prevent Fall (1min): STR DC 12](swept downstream to [room L]/able to reach edge)
[Hide DC 12] to escape the run
[Hide@12] to escape the run
[1 min: Armor Rating DC STR-5](swept downstream to [room L]/able to reach edge)
[Hide 12] to escape the run
[Room L]
[1min: STR DC 12](swept downstream to [room L]/able to reach edge)
[1 min: STR-Armor Rating DC 5](swept downstream to [room L]/able to reach edge)
[12 hr: STR@12](swept downstream to [room L]/able to reach edge)
How does one [WIS@15](fail info/pass info 1)
[ssdsd + 22](i'm failing/oh good)
[ssdsd](-/ds)
[ssdsd](player is Incapacitated for 1d4 rounds/-)
[Con](sleep for 1d6x10 minutes/-)
[Dex](2d6 damage/half)
[CON](lose 1hp every minute/-)
[STR](-/upward thrust dislodges debris - critical: door opens)
[DEX](slide down to pit/-)
[level 2 - room T]
[CON-Armor Rating](1d8 damage/-)
[STR-Armor Rating](swept downstream to [room L]/able to reach edge)
[Dex](-/pull up bracelet with chain)
[paralyze](paralyzed 3d6 turns/-)
[wis](cannot understand/-)
[poison](unconscious 1d6 turns/-)";
// 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/