import re
regex = re.compile(r"0[xX][0-9a-fA-F]+(?=\nwtf)", flags=re.MULTILINE)
test_str = ("1616846098450\n"
"trying : 16633299966633299966633299\n"
"0x4d68c66a4b7ac51f87e22d0e0b70a4ebc7f6286e7834ec3da18c6147f578afe8\n"
"wtf\n"
"0x848fcea771facf657677f1f3a919ab7e43b1f7d0df95bf8375113c5621e063c2\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