I wanted to create a regex which could match the following pattern:
5,000
2.5
25
This is the regex I have thus far:
re.compile('([\d,]+)')
How can I adjust for the .?
Easiest method would just be this:
re.compile('([\d,.]+)')
But this will allow inputs like .... This might be acceptable, since your original pattern allows ,,,. However, if you want to allow only a single decimal point you can do this:
re.compile('([\d,]+.?\d*)')
Note that this won't allow inputs like .5—you'd need to use 0.5 instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With