# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"<img[\w\W]+?srcSet=\"[^\"]+(?<img>https?:\/\/[^\" ]+)"
test_str = "<img data-test=\"v-img\" src=\"https://cdn.dribbble.com/userupload/14099353/file/original-432bffd5a8a059dfee436b0653d1f13d.jpg?resize=752x\" alt=\"\" width=\"3200\" height=\"2400\" sizes=\"(max-width: 767px) 100vw, (max-width: 919px) calc(100vw - 32px), (max-width: 1278px) calc(100vw - 240px), 1024px\" draggable=\"false\" srcSet=\"https://cdn.dribbble.com/userupload/14099353/file/original-432bffd5a8a059dfee436b0653d1f13d.jpg?resize=300x225 300w, https://cdn.dribbble.com/userupload/14099353/file/original-432bffd5a8a059dfee436b0653d1f13d.jpg?resize=400x300 400w, https://cdn.dribbble.com/userupload/14099353/file/original-432bffd5a8a059dfee436b0653d1f13d.jpg?resize=600x450 600w, https://cdn.dribbble.com/userupload/14099353/file/original-432bffd5a8a059dfee436b0653d1f13d.jpg?resize=752x564 752w, https://cdn.dribbble.com/userupload/14099353/file/original-432bffd5a8a059dfee436b0653d1f13d.jpg?resize=1024x768 1024w, https://cdn.dribbble.com/userupload/14099353/file/original-432bffd5a8a059dfee436b0653d1f13d.jpg?resize=1200x900 1200w, https://cdn.dribbble.com/userupload/14099353/file/original-432bffd5a8a059dfee436b0653d1f13d.jpg?resize=1504x1128 1504w, https://cdn.dribbble.com/userupload/14099353/file/original-432bffd5a8a059dfee436b0653d1f13d.jpg?resize=2048x1536 2048w, https://cdn.dribbble.com/userupload/14099353/file/original-432bffd5a8a059dfee436b0653d1f13d.jpg?resize=2400x1800 2400w\" class=\"v-img content-block border-radius-8\" data-v-5e868365>"
matches = re.finditer(regex, test_str, re.MULTILINE)
for matchNum, match in enumerate(matches, start=1):
print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group()))
for groupNum in range(0, len(match.groups())):
groupNum = groupNum + 1
print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.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