const regex = /(?:https?|ftp):\\?\/\\?\/sun2.[^\s\,]+/i;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?:https?|ftp):\\\\?\\\/\\\\?\\\/sun2.[^\\s\\,]+', 'i')
const str = `<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>`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
if ((m = regex.exec(str)) !== null) {
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
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 JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions