import re
regex = re.compile(r"(?i)name\s*=\s*['\"]?date[^>]+content\s*=\s*['\"]?([^'\"]*)['\"]?|content\s*=\s*['\"]?([^\"']*)['\"]?[^>]+name\s*=\s*['\"]?date['\"]?")
test_str = (" <meta name=\"keywords\" content=\"People, Royals\" />\n"
" <meta name=\"news_keywords\" content=\"william,george,charlotte,kate middleton,prinz george,prinz,prinzessin charlotte,royal-family,marys hospitals,royal-fans\" />\n"
" <meta name=\"author\" content=\"Blick\" />\n"
"<meta name=\"date\" content=\"2018-04-23T14:20:42+0200\" />\n"
"<meta name=\"robots\" content=\"index,follow,noodp,noarchive\" />\n"
" <meta name=\"contentId\" content=\"8171954\" />\n"
" <meta name=\"cXenseParse:recs:articleid\" content=\"8171954\"/>\n"
"<meta name=\"contentType\" content=\"news\" />\n"
" <meta name=\"cXenseParse:rag-pagetype\" content=\"news\"/>\n"
"<meta name=\"contentPool\" content=\"web|mobile|app\" />\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