// 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"(?i)(?:https?|ftp):\\?\/\\?\/sun2.[^\s\,]+").unwrap();
let string = "<a aria-label=\"фотография\" onclick=\"return showPhoto('-100714248_457263531', 'wall-100714248_195733', {\"temp\":{\"x\":\"https:\\/\\/sun1.tattelecom-nbc.userapi.com\\/AZsv8R78JOlrmsTJ6NR_NZpKj-RbfbWCPWQ8uA\\/QnMLGnxpnYk.jpg\",\"y\":\"https:\\/\\/sun1.tattelecom-nbc.userapi.com\\/vtKcPNt6Wazn_vcPkvLAMX1MOhMz_hfRgYx28g\\/cXJNEGEn2Lc.jpg\",\"z\":\"https:\\/\\/sun2.tattelecom-nbc.userapi.com\\/oZ0evVUqXklp4UGCisHHFRSaNTEfnnJO_A7lTg\\/ZqD22JRrSyw.jpg\",\"x_\":[\"https:\\/\\/sun1.tattelecom-nbc.userapi.com\\/AZsv8R78JOlrmsTJ6NR_NZpKj-RbfbWCPWQ8uA\\/QnMLGnxpnYk\",359,604],\"y_\":[\"https:\\/\\/sun1.tattelecom-nbc.userapi.com\\/vtKcPNt6Wazn_vcPkvLAMX1MOhMz_hfRgYx28g\\/cXJNEGEn2Lc\",480,807],\"z_\":[\"https:\\/\\/sun2.tattelecom-nbc.userapi.com\\/oZ0evVUqXklp4UGCisHHFRSaNTEfnnJO_A7lTg\\/ZqD22JRrSyw\",587,987],\"base\":\"\"},\"queue\":1}, event)\" style=\"width: 68px; height: 115px;background-image: url(https://sun2.tattelecom-nbc.userapi.com/aMS3yYlzjZF3H6GPY1T5oDAeIqZD5uQv4WveMw/7ToUPNMTnmo.jpg);\" class=\"page_post_thumb_wrap image_cover page_post_thumb_last_column fl_l page_post_thumb_not_single\" data-photo-id=\"-100714248_457263531\"></a>";
// 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/