# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"[^\d,]+|,+\D|\D,+|\d+,\d{3,}|\d{3,}(?:,\d+)?|^,|,$"
test_str = ("Of course, 22d,3 equals 22,3, or A equals (empty string), 12 equals 12, need to remove anything that's not a number and my separator for float is ,\n\n"
"This is a 12 test with 12,34 digits and 123.23 or 123,1 or 123,12 or123,123 and 1234,1 but not 1,234 .html\n\n"
"test-test\n"
"34,344\n"
"34,34\n"
"34,1\n"
"34.1\n"
"1\n"
"1,1\n"
"1,12\n"
"12\n"
"100000\n\n"
"This is a ,comma here and ,,,,,3where ,\n"
",,\n"
",\n"
"This is , a a test 10,2333")
matches = re.finditer(regex, test_str, re.MULTILINE)
for matchNum, match in enumerate(matches, start=1):
print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group()))
for groupNum in range(0, len(match.groups())):
groupNum = groupNum + 1
print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.group(groupNum)))
# Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.
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