// 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#""hash":"(.*?)""#).unwrap();
let string = "[{\"added_on\":1587102956,\"amount_left\":0,\"auto_tmm\":false,\"availability\":-1,\"category\":\"radarr\",\"completed\":1218638934,\"completion_on\":1587108704,\"dl_limit\":-1,\"dlspeed\":0,\"downloaded\":1220894674,\"downloaded_session\":0,\"eta\":8640000,\"f_l_piece_prio\":false,\"force_start\":true,\"hash\":\"87802183fc647548ec6efe18feb16149522f6aa0\",\"last_activity\":1587119220,\"magnet_uri\":\"magnet:?xt=urn:btih:87802183fc647548ec6efe18feb16149522f6aa0&dn=Fantasia%202000%20(1999)%20%5b1080p%5d%20%5bYTS.AG%5d&tr=udp%3a%2f%2ftracker.coppersurfer.tk%3a6969%2fannounce&tr=udp%3a%2f%2f9.rarbg.com%3a2710%2fannounce&tr=udp%3a%2f%2fp4p.arenabg.com%3a1337&tr=udp%3a%2f%2ftracker.leechers-paradise.org%3a6969&tr=udp%3a%2f%2ftracker.internetwarriors.net%3a1337&tr=udp%3a%2f%2ftracker.opentrackr.org%3a1337%2fannounce&tr=udp%3a%2f%2ftracker.zer0day.to%3a1337%2fannounce&tr=udp%3a%2f%2ftracker.leechers-paradise.org%3a6969%2fannounce&tr=udp%3a%2f%2fcoppersurfer.tk%3a6969%2fannounce\",\"max_ratio\":-1,\"max_seeding_time\":-1,\"name\":\"Fantasia 2000 (1999) [1080p] [YTS.AG]\",\"num_complete\":22,\"num_incomplete\":4,\"num_leechs\":0,\"num_seeds\":0,\"priority\":0,\"progress\":1,\"ratio\":0.1782183661159947,\"ratio_limit\":-2,\"save_path\":\"/Volumes/1049/Media/\",\"seeding_time_limit\":-2,\"seen_complete\":1587118087,\"seq_dl\":false,\"size\":1218638934,\"state\":\"forcedUP\",\"super_seeding\":false,\"tags\":\"\",\"time_active\":13224,\"total_size\":1218638934,\"tracker\":\"udp://tracker.coppersurfer.tk:6969/announce\",\"up_limit\":-1,\"uploaded\":217585854,\"uploaded_session\":128831791,\"upspeed\":0}]";
// 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/