I would like to extract numbers from a string such as
There are 1,000 people in those 3 towns.
and get an array like ["1,000", "3"]
.
I got the following number matching Regex from Justin in this question
^[+-]?(\d*|\d{1,3}(,\d{3})*)(\.\d+)?\b$
This works great for checking if it is a number but to make it work on a sentence you need to remove the "^" and "$".
regex101 with start/end defined regex101 without start/end defined
Without the start and end defined you get a bunch of 0 length matches these can easily be discarded but it also now splits any numbers with a comma in them.
How do I make that regex (or a new regex) work on sentences and still find numbers with commas in them.
A bonus would be not having all the 0 length matches as well.