// 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"\[(.*?)\]").unwrap();
let string = "\"The quick, brown fox jumps over a lazy dog. DJs flock by when MTV ax quiz prog.
Junk MTV quiz graced by fox whelps. [Never gonna ] Bawds jog, flick quartz, vex nymphs.
[give you up\\n] Waltz, bad nymph, for quick jigs vex! Fox nymphs grab quick-jived waltz.
Brick quiz whangs jumpy veldt fox. [Never ] Bright vixens jump; [gonna let ] dozy fowl
quack. Quick wafting zephyrs vex bold Jim. Quick zephyrs blow, vexing daft Jim. Charged
[you down\\n] fop blew my junk TV quiz. How quickly daft jumping zebras vex. Two driven
jocks help fax my big quiz. Quick, Baz, get my woven flax jodhpurs! \"Now fax quiz Jack!\"
my brave ghost pled. [Never ] Five quacking zephyrs jolt my wax bed. [gonna ] Flummoxed
by job, kvetching W. zaps Iraq. Cozy sphinx waves quart jug of bad milk. [run around ]
A very bad quack might jinx zippy fowls. Few quips galvanized the mock jury box. Quick
brown dogs jump over the lazy fox. The jay, pig, fox, zebra, and my wolves quack!
[and desert you] Blowzy red vixens fight for a quick jump. Joaquin Phoenix was gazed
by MTV for luck. A wizard’s job is to vex chumps quickly in fog. Watch \"Jeopardy!\",
Alex Trebek's fun TV quiz game.\"";
// 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/