import re
regex = re.compile(r"(<img\s[^>]*?data-src-l\s*=\s*['\"])([^'\"]*?['\"])([^>]*?>)", flags=re.MULTILINE)
test_str = ("<li>\n"
" <a href=\"/WebRoot/products/8020/80203122/bilder/80203122.jpg\">\n"
" <img\n"
" itemprop=\"image\"\n"
" alt=\"Jesus Remember Me - Taize Songs (2CD)\"\n"
" src=\"/WebRoot/AsaphNL/Shops/asaphnl/5422/8F43/62EE/D698/EF8E/4DEB/AED5/3B0E/80203122_xs.jpg\"\n"
" data-src-xs=\"/WebRoot/AsaphNL/Shops/asaphnl/5422/8F43/62EE/D698/EF8E/4DEB/AED5/3B0E/80203122_xs.jpg\"\n"
" data-src-s=\"/WebRoot/products/8020/80203122/bilder/80203122_s.jpg\"\n\n"
" data-src-m=\"/WebRoot/products/8020/80203122/bilder/80203122_m.jpg\"\n\n"
" data-src-l=\"/WebRoot/products/8020/80203122/bilder/80203122.jpg\"\n"
" />\n"
" </a>\n"
" </li>\n\n"
"</ul>")
subst = "$1http://www.asaphshop.nl$2$3"
result = regex.sub(subst, test_str)
if result:
print(result)
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