// 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#""([^"]+)":"#).unwrap();
let string = "{
\"activity:status\": \"BOOKED\",
\"criteria:duration\": 8,
\"criteria:tripFrom\": 1500242400,
\"criteria:tripTo\": 1500933600,
\"intent:booker\": 0.06258322237017303,
\"intent:churnRisk\": 0.3004193725304727,
\"intent:churnRiskText\": \"LOW\",
\"intent:userClass\": \"CUSTOMER\",
\"issues:acs\": 14,
\"issues:total\": 0,
\"revenue\": 2896,
\"tracking:events\": 162,
\"tracking:firstVisit\": 1475320136,
\"tracking:lastVisit\": 1498054362,
\"tracking:sessions30\": 19,
\"tracking:timeSpent\": 10603,
\"value:potentialRevenue\": {
\"mean\": 2880.5258186397987,
\"stddev\": 504.1184773012633,
\"weight\": 1,
\"confidence\": 1
},
\"criteria:occupancy\": {
\"adults\": 2,
\"children\": 2,
\"infants\": 0
}
}";
// 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/