// 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#"balance\"\:\"([0-9]{1,})\"\,\"settings"#).unwrap();
let string = "[200,{\"cookie\":\"623218:b4693930b241d92abcd866afd3a48090ee213570\",\"user\":{\"id\":\"623218\",\"name\":\"null\",\"email\":\"knight-war@hotmail.com\",\"api_key\":\"09cafaaa34299398474bb6bdff7e02a2a7fb6fda\",\"premium\":\"Thu Oct 09 2014 17:39:15 GMT+0000 (UTC)\",\"premium_unix\":\"1412876355\",\"webspace\":53687091200,\"traffic\":{\"current\":1099511627776,\"increase\":0,\"last\":1413569003,\"max\":0},\"balance\":\"0\",\"settings\":{},\"external_id\":\"null\",\"ftp_username\":\"ftp623218\",\"partner\":\"3\",\"partner_last\":\"1413025653\",\"allow_dupe_names\":\"0\"},\"session\":\"45af19f7-4d90-40ad-b90e-d98fa22ba15c\"}]1";
// 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/