// 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#"\s*([JSESSIONID]+)\s*=\s*(?:"([^"])"|([^;"]*))\s*"#).unwrap();
let string = "HTTP/1.1 302 Found
Date: Fri, 10 Jun 2016 21:44:38 GMT
Set-Cookie: JSESSIONID=1n9rk5co2o4xkpr327clod1pu;Path=/genesys;Expires=Sat, 11-Jun-2016 21:44:38 GMT;HttpOnly
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Location: http://192.168.1.200:8010/genesys/admin/login.jsp#/
Content-Length: 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/