# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"<img(?:[\s\w=\"]+)src=\"([^\"]+)\"(?:[\s\w=\"]*)\/?>"
test_str = ("<img src=\"image1.jpg\" width=\"200\" height=\"200\">\n\n"
"<div>\\r\\n<h2 class=\\\"ng-binding\\\" style=\\\"text-align: center;\\\"><span style=\\\"color: #ff0000;\\\">قيولي50 درصدي دانش آموزان در آزمون تيزهوشان</span></h2>\\r\\n</div>\\r\\n<div class=\\\"ng-scope\\\" style=\\\"text-align: center;\\\">\\r\\n<div class=\\\"groupsRowSeperator\\\"> </div>\\r\\n<div id=\\\"contextData\\\">\\r\\n<h3 class=\\\"ng-scope\\\"><span style=\\\"color: #008000;\\\">افتخار آفريني تيزهوشاني </span></h3>\\r\\n<h3 class=\\\"ng-scope\\\"><span style=\\\"color: #800080;\\\">قبولي50 درصدي دانش آموزان دبستان هوشمند شهيد مهدوي در آزمون تيزهوشان سال تحصيلي 99-98 برگ زرين ديگري براي شما اولياي گرامي و همكاران محترم و نتيجه اطميناني بود كه به هم داشتيم.</span></h3>\\r\\n<h3 class=\\\"ng-scope\\\"><span style=\\\"color: #800080;\\\">اين موفقيت بزرگ را به كليه دانش آموزان عزيز ، والدين گرامي ، معلمين دلسوز ، همكاران پرتلاش دبستان هوشمند شهيد مهدوي تبريك و تهنيت عرض مي نمائيم.</span></h3>\\r\\n<p class=\\\"ng-scope\\\"> </p>\\r\\n<p class=\\\"ng-scope\\\"><img src=\\\"http://mahdavi-smart-school.ir/upload/5/akhbar/97-98/IMG-20190805-WA0014.jpg\\\" alt=\\\"\\\" width=\\\"423\\\" height=\\\"1060\\\" /></p>\\r\\n</div>\\r\\n</div>\\r\\n<div class=\\\"CommentBox\\\" style=\\\"text-align: center;\\\"> </div>")
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