import re
regex = re.compile(r"^-?\d{1,3}(?:[,.]\d{3})*[.,]\d{2}$", flags=re.MULTILINE)
test_str = ("2\n"
" // no match\n"
"29.2\n"
" // no match\n"
"2.48\n"
"8.06.16\n"
" // no match\n"
"-2.41\n"
"-.54\n"
" // no match\n"
"4.492\n"
" // no match\n"
"4.194,32\n"
"39,299.39\n"
"329.382,39\n"
"-188.392,49\n"
"293.392,193\n"
" // no match\n"
"-.492.183,33'\n"
" // no match\n"
"3.492.249,11\n"
"29.439.834,13\n"
"-392.492.492,43\n"
"8.06.16\n"
" // no match")
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