Q: Match digits with optional commas and dot What is the regex to match one or more digits with commas for thousands separator, followed by an optional dot and decimals, as in:
Must match
1 
12
123,123
123,123.000
123.123

But not,
123.123,123


A: Sounds to me like you're looking for something like this (see demo):
^\d+(?:,\d{3})*(?:\.\d{3})?$



*

*This allows for multiple comma-separated thousands groups as in 12,345,678.000

*Please note that there are three digits after the period (or none). If instead you'd like to allow one or more, change the \d{3} to a \d+
Explain Regex
^                        # the beginning of the string
\d+                      # digits (0-9) (1 or more times (matching
                         # the most amount possible))
(?:                      # group, but do not capture (0 or more times
                         # (matching the most amount possible)):
  ,                      #   ','
  \d{3}                  #   digits (0-9) (3 times)
)*                       # end of grouping
(?:                      # group, but do not capture (optional
                         # (matching the most amount possible)):
  \.                     #   '.'
  \d{3}                  #   digits (0-9) (3 times)
)?                       # end of grouping
$                        # before an optional \n, and the end of the
                         # string

