// 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)<text[^>]+>([^<]+)<\/text>").unwrap();
let string = "This XML file does not appear to have any style information associated with it. The document tree is shown below.
<transcript>
<text start=\"9.462\" dur=\"1.123\">Aaaah</text>
<text start=\"10.585\" dur=\"1.646\">It's Rewind time.</text>
<text start=\"12.341\" dur=\"3.721\">If I controlled Rewind I would want</text>
<text start=\"16.062\" dur=\"3.161\">Fortnite and Marques Brownlee.</text>
<text start=\"24.834\" dur=\"1.014\">Is this what you wanted?</text>
<text start=\"25.848\" dur=\"1.887\">You know who I would have asked for?</text>
<text start=\"27.944\" dur=\"1.557\">Quit horsing around.</text>
<text start=\"30.239\" dur=\"2.217\">Play me some of that jumping music.</text>
<text start=\"32.676\" dur=\"1.336\">Did you say jumping music?</text>
<text start=\"34.072\" dur=\"1.266\">Jumping music?</text>
<text start=\"39.622\" dur=\"1.28\">Everybody! Off!</text>
<text start=\"48.192\" dur=\"1.847\">Not even a thank you?!</text>
<text start=\"57.676\" dur=\"1.762\">Is that Marques?</text>
<text start=\"59.438\" dur=\"1.597\">I want Liza!</text>
<text start=\"64.405\" dur=\"3.644\">Yeaaaaaahhhh!!!!</text>
<text start=\"70.507\" dur=\"5.51\">So guys, apparently we control Rewind this year.</text>
<text start=\"76.017\" dur=\"4.842\">
Y'all we can do whatever we want. What do we do?
</text>
<text start=\"85.011\" dur=\"3.299\">There's one thing this video needs.</text>
<text start=\"88.31\" dur=\"1.989\">K-pop!</text>
<text start=\"108.973\" dur=\"2.159\">Can I have a Royal Wedding?</text>
<text start=\"111.132\" dur=\"1.73\">Yeah, but you're marrying Bongo Cat.</text>
<text start=\"112.863\" dur=\"1\">Wait, what?</text>
<text start=\"122.334\" dur=\"1.587\">Rewind needs more science.</text>
<text start=\"123.921\" dur=\"1.473\">Can we do an experiment?</text>
<text start=\"125.758\" dur=\"2.359\">I love that. Melting lipstick.</text>
<text start=\"133.23\" dur=\"1.332\">I want to eat something.</text>
<text start=\"135.102\" dur=\"1.743\">Mukbang!</text>
<text start=\"136.845\" dur=\"1.98\">Yes, let's do it in Korea!</text>
<text start=\"145.191\" dur=\"1.307\">Gallop, what do you want?</text>
<text start=\"154.964\" dur=\"2.042\">Marshmello needs to be in this video.</text>
<text start=\"158.036\" dur=\"1.298\">Who is Marshmello?</text>
<text start=\"159.675\" dur=\"1.835\">How about yodeling kid?</text>
<text start=\"162.104\" dur=\"1.29\">With Adam Rippon!</text>
<text start=\"182.612\" dur=\"2.332\">Guys, let's do the In My Feelings challenge.</text>
<text start=\"184.944\" dur=\"1.014\">Right!</text>
<text start=\"188.239\" dur=\"1.193\">I love this song!</text>
<text start=\"189.432\" dur=\"1.68\">Let's hear the remix!</text>
<text start=\"222.998\" dur=\"2.064\">Wait, wait, wait. Hold on, hold on.</text>
<text start=\"225.062\" dur=\"3.274\">
You know who really needs to be in this Rewind video?
</text>
<text start=\"228.336\" dur=\"3.062\">
Everyone who managed to do something bigger than themselves this year.
</text>
<text start=\"231.398\" dur=\"3.266\">
Found a way to help the causes that matter to them most.
</text>
<text start=\"234.664\" dur=\"3.423\">
To everyone who proved it's ok to talk about mental health this year.
</text>
<text start=\"238.087\" dur=\"3.443\">
Showing our viewers that it's ok to go through tough times like that.
</text>
<text start=\"241.53\" dur=\"4.122\">
It takes a lot of bravery to be that vulnerable and I'm so proud of this community.
</text>
<text start=\"245.652\" dur=\"4.046\">
I think this year's Rewind should celebrate the fierce, fabulous
</text>
<text start=\"249.698\" dur=\"1.893\">and empowering art of drag.</text>
<text start=\"251.591\" dur=\"3.027\">
I want to see all of you be your own kind of beautiful.
</text>
<text start=\"254.618\" dur=\"3.121\">
And to those people who have raised money in the field of education.
</text>
<text start=\"257.739\" dur=\"4.628\">
Can we also give a moment to Asian representation in entertainment this year?
</text>
<text start=\"262.367\" dur=\"1.393\">Major strides were made.</text>
<text start=\"263.76\" dur=\"2.018\">
And to the people who put aside their differences.
</text>
<text start=\"265.778\" dur=\"1.837\">Yeah, and created something really special.</text>
<text start=\"267.615\" dur=\"3.769\">
Here's to all women in 2018 for finding their voices.
</text>
<text start=\"271.384\" dur=\"3.614\">
It's nice seeing how women grew and were empowered.
</text>
<text start=\"274.998\" dur=\"2.778\">
Can we give a moment to working moms? Let's do it!
</text>
<text start=\"277.776\" dur=\"4.5\">
To everyone who taught, or learned, something new this year.
</text>
<text start=\"282.276\" dur=\"3.061\">
And to all the refugees and anyone looking for a home.
</text>
<text start=\"285.337\" dur=\"4.201\">
All of us should send a toast to the kids who follow their dreams.
</text>
<text start=\"289.538\" dur=\"4.888\">
I want to thank the whole community that always supports during our best and worst.
</text>
<text start=\"294.426\" dur=\"2.262\">We are a family, we are a team.</text>
<text start=\"296.688\" dur=\"1.772\">Family is everything.</text>
<text start=\"298.46\" dur=\"3.764\">
I want to give a moment to everyone who supported me when I got sick.
</text>
<text start=\"302.224\" dur=\"4.087\">
All of the comments and messages I got made me feel like I wasn't alone.
</text>
<text start=\"307.222\" dur=\"2.177\">We're forgetting something.</text>
<text start=\"311.312\" dur=\"3.11\">I think we should read the comments.</text>
<text start=\"322.401\" dur=\"4.34\">
Yeah I have a feeling this is going to get a little bit crazy.
</text>
<text start=\"326.741\" dur=\"2.77\">Let's give the people what they want.</text>
<text start=\"413.038\" dur=\"1.51\">Aaaahhh</text>
<text start=\"417.803\" dur=\"2.29\">That's hot, that's hot.</text>
</transcript>";
// 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/