// 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"Request\:\s\[(?P<req_ip>\d+\.\d+\.\d+\.\d+)").unwrap();
let string = "Jun 20, 2016 17:59:39 [0x7f16b541b700] DEBUG - Request: [192.168.1.88:54368] GET /:/timeline?ratingKey=68803&key=%2Flibrary%2Fmetadata%2F68803&state=paused&playQueueItemID=2831&time=1360507&duration=5694741 (34 live) TLS GZIP
Jun 20, 2016 17:59:39 [0x7f16b541b700] DEBUG - Auth: We found auth token (xxxxxxxxxxxxxxxxxxxx), enabling token-based authentication.
Jun 20, 2016 17:59:39 [0x7f16b541b700] DEBUG - Auth: Came in with a super-token, authorization succeeded.
Jun 20, 2016 17:59:39 [0x7f16b541b700] DEBUG - Client [iqzupp52ref65urd69nng66r] reporting timeline state paused, progress of 1360507/5694741ms for guid=, ratingKey=68803 url=, key=/library/metadata/68803, containerKey=, metadataId=68803
Jun 20, 2016 17:59:39 [0x7f16b541b700] DEBUG - Play progress on 68803 'Kung Fu Panda 3' - got played 1360507 ms by account 1!
Jun 20, 2016 17:59:39 [0x7f16b541b700] DEBUG - [Now] User is sydvishus (ID: 1)
Jun 20, 2016 17:59:39 [0x7f16b541b700] DEBUG - [Now] Device is Chrome (Plex Web (Chrome)).
Jun 20, 2016 17:59:39 [0x7f16b541b700] DEBUG - [Now] Updated play state for /library/metadata/68803.
Jun 20, 2016 17:59:39 [0x7f16c1bff700] DEBUG - Completed: [192.168.1.88:54368] GET /:/timeline?ratingKey=68803&key=%2Flibrary%2Fmetadata%2F68803&state=paused&playQueueItemID=2831&time=1360507&duration=5694741 (34 live) TLS GZIP 4ms 276 bytes 200 (pipelined: 20)";
// 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/