// 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"[0-9]*.?").unwrap();
let string = "393. A gypsy caravan passes. They might have interesting items for sale or trade, but
they have touchy tempers and strange customs. They might even want to capture a
PC or pet to sell in the next town.
394. A thief tries to infiltrate the party to steal from them.
395. A fallen tree blocks the road ahead. You notice a path going around it but cannot
see the other side.
396. An nearby tree is infested with animated objects that attack travelers that disturb
their swarm.
3979. A press gang accosts travelers just down the road.
398. A mounted patrol of soldiers ask travellers what they have seen, then pass on the
King's warning to be law-abiding.
399. An otherwise empty stretch of highway, with two rival taverns facing each other
across the road. The publicans try to outdo each other loudly on the discounts and
benefits of their respective establishments to the party. Both seem desperate for
customers. ";
// result will be a tuple containing the start and end indices for the first match in the string
let result = regex.captures(string);
let (start, end) = match result {
Some((s, e)) => (s, e),
None => {
// ...
}
};
println!("{}", &string[start, end]);
}
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/