# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"(?:https?|ftp):\\?\/\\?\/sun2.[^\s\,]+"
test_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>"
matches = re.search(regex, test_str, re.IGNORECASE)
if matches:
print ("Match was found at {start}-{end}: {match}".format(start = matches.start(), end = matches.end(), match = matches.group()))
for groupNum in range(0, len(matches.groups())):
groupNum = groupNum + 1
print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = matches.start(groupNum), end = matches.end(groupNum), group = matches.group(groupNum)))
# Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.
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 Python, please visit: https://docs.python.org/3/library/re.html