import re
regex = re.compile(r"([a-z\.]+):\d", flags=re.MULTILINE | re.IGNORECASE)
test_str = ("9 40 0.5752 2 0.0000 *BRK.B:23.42:24.08:-2.82% PFE:28.05:26.94:3.97%\n"
"9 40 0.5752 2 0.0000 *NOV:23.42:24.08:-2.82%\n"
"3 50 0.5752 7 0.0000 C:23.42:24.08:-2.82% *AAPL:28.05:26.94:3.97%% *MMM:28.05:26.94:3.97%")
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