// 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#"<td class="result_text"> <a href="\/title\/tt([0-9]+)\/\?ref_=[a-zA-Z0-9_]+" >((?:(?!<\/a>).)*?)<\/a>"#).unwrap();
let string = "
<tr class=\"findResult odd\"> <td class=\"primary_photo\"> <a href=\"/title/tt4158110/?ref_=fn_al_tt_1\" ><img src=\"http://ia.media-imdb.com/images/M/MV5BMTg3OTQ2NzAzN15BMl5BanBnXkFtZTgwMDUyNjY3NTE@._V1_UX32_CR0,0,32,44_AL_.jpg\" /></a> </td> <td class=\"result_text\"> <a href=\"/title/tt4158110/?ref_=fn_al_tt_1\" >Mr. Robot</a> (2015) (TV Series) </td> </tr><tr class=\"findResult even\"> <td class=\"primary_photo\"> <a href=\"/title/tt4730026/?ref_=fn_al_tt_2\" ><img src=\"http://ia.media-imdb.com/images/M/MV5BMjIzOTE2MjIwMl5BMl5BanBnXkFtZTgwMzQ1ODU0NjE@._V1_UY44_CR17,0,32,44_AL_.jpg\" /></a> </td> <td class=\"result_text\"> <a href=\"/title/tt4730026/?ref_=fn_al_tt_2\" >eps1.7_wh1ter0se.m4v</a> (2015) (TV Episode) <br/><small>- <a href=\"/title/tt4158110/?ref_=fn_al_tt_2a\" >Mr. Robot</a> (2015) (TV Series) </small> </td> </tr><tr class=\"findResult odd\"> <td class=\"primary_photo\"> <a href=\"/title/tt4730002/?ref_=fn_al_tt_3\" ><img src=\"http://ia.media-imdb.com/images/M/MV5BNDMyODE0MDcyOV5BMl5BanBnXkFtZTgwMDA4MzgxNjE@._V1_UY44_CR17,0,32,44_AL_.jpg\" /></a> </td> <td class=\"result_text\"> <a href=\"/title/tt4730002/?ref_=fn_al_tt_3\" >eps1.2_d3bug.mkv</a> (2015) (TV Episode) <br/><small>- <a href=\"/title/tt4158110/?ref_=fn_al_tt_3a\" >Mr. Robot</a> (2015) (TV Series) </small> </td> </tr><tr class=\"findResult even\"> <td class=\"primary_photo\"> <a href=\"/title/tt4652838/?ref_=fn_al_tt_4\" ><img src=\"http://ia.media-imdb.com/images/M/MV5BMTY4MDgwMzEwMl5BMl5BanBnXkFtZTgwMzgzMzk5NTE@._V1_UY44_CR17,0,32,44_AL_.jpg\" /></a> </td> <td class=\"result_text\"> <a href=\"/title/tt4652838/?ref_=fn_al_tt_4\" >eps1.0_hellofriend.mov</a> (2015) (TV Episode) <br/><small>- <a href=\"/title/tt4158110/?ref_=fn_al_tt_4a\" >Mr. Robot</a> (2015) (TV Series) </small> </td> </tr><tr class=\"findResult odd\"> <td class=\"primary_photo\"> <a href=\"/title/tt4799588/?ref_=fn_al_tt_5\" ><img src=\"http://ia.media-imdb.com/images/M/MV5BNjAyNzM1NzkzOV5BMl5BanBnXkFtZTgwOTI3MDk1NjE@._V1_UY44_CR17,0,32,44_AL_.jpg\" /></a> </td> <td class=\"result_text\"> <a href=\"/title/tt4799588/?ref_=fn_al_tt_5\" >eps1.8_m1rr0r1ng.qt</a> (2015) (TV Episode) <br/><small>- <a href=\"/title/tt4158110/?ref_=fn_al_tt_5a\" >Mr. Robot</a> (2015) (TV Series) </small> </td> </tr><tr class=\"findResult even\"> <td class=\"primary_photo\"> <a href=\"/title/tt4730012/?ref_=fn_al_tt_6\" ><img src=\"http://ia.media-imdb.com/images/M/MV5BMzQ5NTg5ODQyMV5BMl5BanBnXkFtZTgwNjcxNzMzNjE@._V1_UY44_CR17,0,32,44_AL_.jpg\" /></a> </td> <td class=\"result_text\"> <a href=\"/title/tt4730012/?ref_=fn_al_tt_6\" >eps1.4_3xpl0its.wmv</a> (2015) (TV Episode) <br/><small>- <a href=\"/title/tt4158110/?ref_=fn_al_tt_6a\" >Mr. Robot</a> (2015) (TV Series) </small> </td> </tr><tr class=\"findResult odd\"> <td class=\"primary_photo\"> <a href=\"/title/tt4659980/?ref_=fn_al_tt_7\" ><img src=\"http://ia.media-imdb.com/images/M/MV5BMjA1MjYxNzczM15BMl5BanBnXkFtZTgwMjU4MzgxNjE@._V1_UY44_CR17,0,32,44_AL_.jpg\" /></a> </td> <td class=\"result_text\"> <a href=\"/title/tt4659980/?ref_=fn_al_tt_7\" >eps1.3_da3m0ns.mp4</a> (2015) (TV Episode) <br/><small>- <a href=\"/title/tt4158110/?ref_=fn_al_tt_7a\" >Mr. Robot</a> (2015) (TV Series) </small> </td> </tr><tr class=\"findResult even\"> <td class=\"primary_photo\"> <a href=\"/title/tt4686038/?ref_=fn_al_tt_8\" ><img src=\"http://ia.media-imdb.com/images/M/MV5BMTg0NTkwMTc1NF5BMl5BanBnXkFtZTgwNzY3MzgxNjE@._V1_UY44_CR17,0,32,44_AL_.jpg\" /></a> </td> <td class=\"result_text\"> <a href=\"/title/tt4686038/?ref_=fn_al_tt_8\" >eps1.1_ones-and-zer0es.mpeg</a> (2015) (TV Episode) <br/><small>- <a href=\"/title/tt4158110/?ref_=fn_al_tt_8a\" >Mr. Robot</a> (2015) (TV Series) </small> </td> </tr><tr class=\"findResult odd\"> <td class=\"primary_photo\"> <a href=\"/title/tt4730014/?ref_=fn_al_tt_9\" ><img src=\"http://ia.media-imdb.com/images/M/MV5BMTc2NDc0ODc3MV5BMl5BanBnXkFtZTgwODYxNzMzNjE@._V1_UY44_CR17,0,32,44_AL_.jpg\" /></a> </td> <td class=\"result_text\"> <a href=\"/title/tt4730014/?ref_=fn_al_tt_9\" >eps1.5_br4ve-trave1er.asf</a> (2015) (TV Episode) <br/><small>- <a href=\"/title/tt4158110/?ref_=fn_al_tt_9a\" >Mr. Robot</a> (2015) (TV Series) </small> </td> </tr><tr class=\"findResult even\"> <td class=\"primary_photo\"> <a href=\"/title/tt4652854/?ref_=fn_al_tt_10\" ><img src=\"http://ia.media-imdb.com/images/M/MV5BMzUyMzIxMDY2N15BMl5BanBnXkFtZTgwNTU3MDk1NjE@._V1_UY44_CR17,0,32,44_AL_.jpg\" /></a> </td> <td class=\"result_text\"> <a href=\"/title/tt4652854/?ref_=fn_al_tt_10\" >eps1.9_zer0-day.avi</a> (2015) (TV Episode) <br/><small>- <a href=\"/title/tt4158110/?ref_=fn_al_tt_10a\" >Mr. Robot</a> (2015) (TV Series) </small> </td> </tr></table>
<div class=\"findMoreMatches\">";
// 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/