// 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)"title":\s*"([^"]*\bSword\b[^"]*)""#).unwrap();
let string = "
{
\"store\": {
\"book\": [
{
\"category\": \"reference\",
\"author\": \"Nigel Rees\",
\"title\": \"Sayings of the Century\",
\"price\": 8.95
},
{
\"category\": \"fiction\",
\"author\": \"Evelyn Waugh\",
\"title\": \"Sword of Honour\",
\"price\": 12.99
},
{
\"category\": \"fiction\",
\"author\": \"Herman Melville\",
\"title\": \"Moby Dick\",
\"isbn\": \"0-553-21311-3\",
\"price\": 8.99
},
{
\"category\": \"fiction\",
\"author\": \"J. R. R. Tolkien\",
\"title\": \"The Lord of the Rings\",
\"isbn\": \"0-395-19395-8\",
\"price\": 22.99
}
],
\"bicycle\": {
\"color\": \"red\",
\"price\": 19.95
}
},
\"expensive\": 10
}
";
// 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/