I’ve been using a standard ([0-9]+) pattern to match numbers in a string, but have a strange edge case now. I want to match the following:
123
456
.123
123.
%123
31st
14th
2nd
100.55
555.10
In the above cases, the non-numeric characters are:
.
%
s
h
n
d
But they could be a variety of characters.
Thoughts?
JS or PHP would be great.
I tried to create several rules for all cases :
Then mixed :
If you want something shorter, you can simply use
([%.\dshnd]+), but this will catch many non-wanted entries, like%%123%%.