Your string start with one white-space and end with two,when using
Could be written like this
Or if strip of white-space it will also work.
^
and $
it most match the begin/end of string exactly on each line.Could be written like this
numRegex = re.compile(r"^\s\d{1,3}(,(\d{3})).*$")
Or if strip of white-space it will also work.
import re numRegex=re.compile(r"^\d{1,3}(,(\d{3}))*$") mo = numRegex.search(" 12,124,123,221 ".strip()) print(mo.group())