// 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#"\"year\"\:(\d{4})\,"#).unwrap();
let string = "{\"total_pages\":1,\"total_count\":3,\"per_page\":60,\"page\":1,\"data\":[{\"id\":\"524414\",\"type\":\"subtitle\",\"attributes\":{\"subtitle_id\":\"524414\",\"language\":\"ro\",\"download_count\":1421,\"new_download_count\":1,\"hearing_impaired\":false,\"hd\":false,\"fps\":25.0,\"votes\":0,\"ratings\":0.0,\"from_trusted\":false,\"foreign_parts_only\":false,\"upload_date\":\"2010-03-07T08:17:40Z\",\"ai_translated\":false,\"machine_translated\":false,\"release\":\"Casino Royale - oo7\",\"comments\":\"AUTOLOAD AUTOUPLOAD\",\"legacy_subtitle_id\":3650579,\"uploader\":{\"uploader_id\":3282,\"name\":\"os-auto\",\"rank\":\"Application Developers\"},\"feature_details\":{\"feature_id\":518630,\"feature_type\":\"Movie\",\"year\":1967,\"title\":\"Casino Royale\",\"movie_name\":\"1967 - Casino Royale\",\"imdb_id\":61452,\"tmdb_id\":12208},\"url\":\"https://www.opensubtitles.com/ro/subtitles/legacy/3650579\",\"related_links\":{\"label\":\"All subtitles for Casino Royale\",\"url\":\"https://www.opensubtitles.com/ro/movies/1967-casino-royale\",\"img_url\":\"https://s9.osdb.link/features/0/3/6/518630.jpg\"},\"files\":[{\"file_id\":579397,\"cd_number\":1,\"file_name\":\"Casino Royale - oo7.sub\"}],\"moviehash_match\":true}},{\"id\":\"522774\",\"type\":\"subtitle\",\"attributes\":{\"subtitle_id\":\"522774\",\"language\":\"es\",\"download_count\":1003,\"new_download_count\":1,\"hearing_impaired\":false,\"hd\":false,\"fps\":25.0,\"votes\":2,\"ratings\":9.5,\"from_trusted\":false,\"foreign_parts_only\":false,\"upload_date\":\"2003-12-18T23:00:00Z\",\"ai_translated\":false,\"machine_translated\":false,\"release\":\"Casino Royale (1967)\",\"comments\":null,\"legacy_subtitle_id\":59217,\"uploader\":{\"uploader_id\":8092,\"name\":\"ShooCat (a)\",\"rank\":\"bronze member\"},\"feature_details\":{\"feature_id\":518630,\"feature_type\":\"Movie\",\"year\":1967,\"title\":\"Casino Royale\",\"movie_name\":\"1967 - Casino Royale\",\"imdb_id\":61452,\"tmdb_id\":12208},\"url\":\"https://www.opensubtitles.com/es/subtitles/legacy/59217\",\"related_links\":{\"label\":\"All subtitles for Casino Royale\",\"url\":\"https://www.opensubtitles.com/es/movies/1967-casino-royale\",\"img_url\":\"https://s9.osdb.link/features/0/3/6/518630.jpg\"},\"files\":[{\"file_id\":577519,\"cd_number\":1,\"file_name\":\"Casino Royale (SPA).srt\"}],\"moviehash_match\":true}},{\"id\":\"525409\",\"type\":\"subtitle\",\"attributes\":{\"subtitle_id\":\"525409\",\"language\":\"es\",\"download_count\":432,\"new_download_count\":2,\"hearing_impaired\":false,\"hd\":false,\"fps\":25.0,\"votes\":0,\"ratings\":0.0,\"from_trusted\":false,\"foreign_parts_only\":false,\"upload_date\":\"2014-05-04T22:40:02Z\",\"ai_translated\":false,\"machine_translated\":false,\"release\":\"James Bond - 007 - Casino Royale -1967\",\"comments\":\"\",\"legacy_subtitle_id\":5657430,\"uploader\":{\"uploader_id\":3282,\"name\":\"os-auto\",\"rank\":\"Application Developers\"},\"feature_details\":{\"feature_id\":518630,\"feature_type\":\"Movie\",\"year\":1967,\"title\":\"Casino Royale\",\"movie_name\":\"1967 - Casino Royale\",\"imdb_id\":61452,\"tmdb_id\":12208},\"url\":\"https://www.opensubtitles.com/es/subtitles/legacy/5657430\",\"related_links\":{\"label\":\"All subtitles for Casino Royale\",\"url\":\"https://www.opensubtitles.com/es/movies/1967-casino-royale\",\"img_url\":\"https://s9.osdb.link/features/0/3/6/518630.jpg\"},\"files\":[{\"file_id\":580507,\"cd_number\":1,\"file_name\":\"James Bond - 007 - Casino Royale -1967-spa.srt\"}],\"moviehash_match\":true}}]}";
// 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/