// 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|url)\\": \\"[^"]*\\""#).unwrap();
let string = "1. Есть строки в текстовом файле: \"title\": \"разный текст\"
Найти всё в этом файле.
2. Есть строки в текстовом файле:
\"url\": \"разный текст\"
Найти всё в этом файле.
3. Есть всё в общей строке в текстовом файле:
\"title\": \"разный текст\", \"url\": \"разный текст\"
[{\"hostName\": \"youtube\", \"name\": \"Rock & Roll 50's Mix\", \"type\": \"VIDEO\", \"iconimage\": \"https://i.ytimg.com/vi/gLzn8nDVSo8/hq720.jpg?sqp=-...\", \"resolver\": \"youtube\", \"data\": \"{\\\"category\\\": \\\"video\\\", \\\"name\\\": \\\"category\\\", \\\"title\\\": \\\"Rock & Roll 50's Mix\\\", \\\"url\\\": \\\"http://www.youtube.com/watch?v=gLzn8nDVSo8\\\", \\\"time\\\": \\\"9 \\\\u043b\\\\u0435\\\\u0442 \\\\u043d\\\\u0430\\\\u0437\\\\u0430\\\\u0434\\\", \\\"desc\\\": \\\"Duration: 11:38 | 71\\\\u00a0528\\\\u00a0835 \\\\u043f\\\\u0440\\\\u043e\\\\u0441\\\\u043c\\\\u043e\\\\u0442\\\\u0440\\\\u043e\\\\u0432 | 9 \\\\u043b\\\\u0435\\\\u0442 \\\\u043d\\\\u0430\\\\u0437\\\\u0430\\\\u0434\\\\ndjdirtybeat\\\\nPLEASE LIKE MY FACEBOOK PAGE, Download Here https://soundcloud.com/mauricio-villegas-12\\\\u00a0...\\\", \\\"type\\\": \\\"video\\\", \\\"icon\\\": \\\"https://i.ytimg.com/vi/gLzn8nDVSo8/hq720.jpg?sqp=-...\"}\", \"description\": \"Duration: 11:38 | 71\\u00a0528\\u00a0835 \\u043f\\u0440\\u043e\\u0441\\u043c\\u043e\\u0442\\u0440\\u043e\\u0432 | 9 \\u043b\\u0435\\u0442 \\u043d\\u0430\\u0437\\u0430\\u0434\\ndjdirtybeat\\nPLEASE LIKE MY FACEBOOK PAGE, Download Here https://soundcloud.com/mauricio-villegas-12\\u00a0...\"}, {\"hostName\": \"youtube\", \"name\": \"Free - All Right Now\", \"type\": \"VIDEO\", \"iconimage\": \"https://i.ytimg.com/vi/YExuLkIaQ7U/hq720.jpg?sqp=-...\", \"resolver\": \"youtube\", \"data\": \"{\\\"category\\\": \\\"video\\\", \\\"name\\\": \\\"category\\\", \\\"title\\\": \\\"Free - All Right Now\\\", \\\"url\\\": \\\"http://www.youtube.com/watch?v=YExuLkIaQ7U\\\", \\\"time\\\": \\\"11";
// 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/