I'm having a string and trying to find all numbers such as 1, -1.5, .5, etc. I already found this question with very helpful answers. The only problem I have is that all these solution seem to match "too much". For example, the match "17" in "MH17". How can I extend any of the proposed solution so that a number cannot start with (or contain) a letter?
Asked
Active
Viewed 117 times
1 Answers
2
I rewrite the original regex: fix +/- bug and exclude the case starting with letter
(?<=\s)[+-]?\d+(?:.\d)?\d*
Also please find the demo

HMK
- 564
- 6
- 14
-
1+1, but you can simplify it a bit with `(?<=\s)[+-]?\d+(?:.\d+)?` – The Guy with The Hat Aug 07 '14 at 02:40
-
2
-
-