import re
regex = re.compile(r"background-image:\s*(url\((?!data)[^)]+\))")
test_str = ("background-image: url(\"img/home_bbbbbb_14.png\");\n"
"background-image: url(img/home_bbbbbb_14.png);\n"
"background-image: url(images/home_bbbbbb_14.png);\n"
"background-image: url('images/home_bbbbbb_14.png');\n"
"background-image: url(\"images/home_bbbbbb_14.png\");\n"
"background-image: url(home_bbbbbb_14.png);\n"
"background-image: url('home_bbbbbb_14.png');\n"
"background-image: url(\"home_bbbbbb_14.png\");\n"
"background-image: url(\"../img/home_bbbbbb_14.png\");\n"
"background-image: url(\"./img/home_bbbbbb_14.png\");\n"
"background-image: url(\"../../img/home_bbbbbb_14.png\");\n"
" background-image: url(data:image/svg+xml;base64,PHN2ZyBmaWxsPSIjMDAwMDAwIiBoZWlnaHQ9IjI0IiB2aWV3Qm94PSIwIDAgMjQgMjQiIHdpZHRoPSIyNCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4gICAgPHBhdGggZD0iTTAgMGgyNHYyNEgweiIgZmlsbD0ibm9uZSIvPiAgICA8cGF0aCBkPSJNMTIgOGMtMi4yMSAwLTQgMS43OS00IDRzMS43OSA0IDQgNCA0LTEuNzkgNC00LTEuNzktNC00LTR6bS03IDdIM3Y0YzAgMS4xLjkgMiAyIDJoNHYtMkg1di00ek01IDVoNFYzSDVjLTEuMSAwLTIgLjktMiAydjRoMlY1em0xNC0yaC00djJoNHY0aDJWNWMwLTEuMS0uOS0yLTItMnptMCAxNmgtNHYyaDRjMS4xIDAgMi0uOSAyLTJ2LTRoLTJ2NHoiLz48L3N2Zz4=);\n")
matches = regex.finditer(test_str)
for match_num, match in enumerate(matches, start=1):
print(f"Match {match_num} was found at {match.start()}-{match.end()}: {match.group()}")
for group_num, group in enumerate(match.groups(), start=1):
print(f"Group {group_num} found at {match.start(group_num)}-{match.end(group_num)}: {group}")
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