I'm trying to write a regex that captures all the numbers in a string BUT only if the string ends with numbers.
I worked out the pattern would require a repeating capture group:
^(\D*(\d+))+$
So
- the string starts
- there are 0 or more non-digit characters
- then 1 or more digits (which we capture)
- that pattern repeats until the end of the string
My problem is that it seems that in repeated capture groups you only get the last match returned to you. (demo)
Can anyone show me where I'm going wrong?