import re
regex = re.compile(r"[^noscript\>]<style[^>]*>([^<]+)?<[\s\/]+style>")
test_str = ("<!DOCTYPE html>\n"
"<html lang=\"en-US\">\n"
"<head>\n"
" <meta charset=\"UTF-8\">\n"
" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, viewport-fit=cover\" /> \n"
" <style type=\"text/css\"></style>\n"
"<noscript><style>\n\n"
"< / style></noscript>\n"
" <!-- Twitter Cards Meta by USM STARTS-->\n"
" <meta name=\"twitter:card\" content=\"summary\" />\n\n"
" \n"
" <style type=\"text/css\">.recentcomments a{display:inline !important;padding:0 !important;margin:0 !important;}</style>\n\n"
"<link rel=\"pingback\" href=\"/xmlrpc.php\">\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