I need some help with writing a regex to match only numbers/number groups in a string:
8000 30 4000 should match 8000 30 4000
ABC13 8000 3999 2999 Comment should match [space]8000 3999 2999[space]
ABC13 80 55 5600 6000 2700 SDR3 Comment should match [space]80 55 5600 6000 2700[space]
I have tried this so far:
([^a-zA-Z]+[^0-9]{0,2})+(\s*\d{0,4}\s*)
I think you are overthinking this a bit. And you have also got some catastrophic backtracking in there. All you need spaces, digits and a wordboundary:
This will work work for all three cases. The
\s*capture any optional spaces along the way, while word boundary\bmakes sure, that the second and third case do not include the13in the match.If you want to make sure that every number has at most 4 digits: