// 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#"(?m)(?<=\btrackingID\b=)(\s*[^;\r\n]*)|\\"code\\":\\"([^\\"\r\n]*)|(\\"status\\"):(\d*)|\\"msg:([^\\"\r\n]*)"#).unwrap();
let string = "ErrorString : trackingID=jskdf-77sdkj-oij4-kerj43-lklfds; key1=lksfjsdkjfkslkdjf;key2=skjfjdkfj43jrkjskd;key4=lksfjsdkjfkslkdjf;key4=skjfjdkfj43jrkjskd;{\\\"info\\\":{\\\"details\\\":[{\\\"code\\\":\\\"ABC23423\\\",\\\"messages\\\":\\\"msg:INVALID_ERROR\\\",\\\"timeStamp\\\":\\\"2019-08-30T15:03:43.668Z\\\"}],\\\"$httpStatus\\\":400},\\\"status\\\":400,\\\"test\\\":\\\"ABC2342fdsff3\\\"
ErrorString : key1=lksfjsdkjfkslkdjf;key2=skjfjdkfj43jrkjskd;key4=lksfjsdkjfkslkdjf;key4=skjfjdkfj43jrkjskd;{\\\"info\\\":{\\\"details\\\":[{\\\"code\\\":\\\"ABC23423\\\",\\\"timeStamp\\\":\\\"2019-08-30T15:03:43.668Z\\\"}],\\\"$httpStatus\\\":400},\\\"messages\\\":\\\"msg:INVALID_ERROR\\\",\\\"status\\\":400,\\\"test\\\":\\\"ABC2342fdsff3\\\"trackingID=jskdf-77sdkj-oij4-kerj43-lklfds;
ErrorString : trackingID=jskdf-77sdkj-oij4-kerj43-lklfds; key1=lksfjsdkjfkslkdjf;key2=skjfjdkfj43jrkjskd;key4=lksfjsdkjfkslkdjf;key4=skjfjdkfj43jrkjskd;{\\\"info\\\":{\\\"details\\\":[{\\\"code\\\":\\\"ABC23423\\\",\\\"timeStamp\\\":\\\"2019-08-30T15:03:43.668Z\\\"}],\\\"status\\\":400,\\\"$httpStatus\\\":400},\\\"messages\\\":\\\"msg:INVALID_ERROR\\\",\\\"test\\\":\\\"ABC2342fdsff3\\\"";
// result will be an iterator over tuples containing the start and end indices for each match in the string
let result = regex.captures_iter(string);
for mat in result {
println!("{:?}", mat);
}
}
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/