1

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?

Community
  • 1
  • 1
Christian
  • 3,239
  • 5
  • 38
  • 79

1 Answers1

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