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?

1
  • Can you provide valid and invalid cases of matching and what have you tried? Commented Aug 7, 2014 at 2:19

1 Answer 1

2

I rewrite the original regex: fix +/- bug and exclude the case starting with letter

(?<=\s)[+-]?\d+(?:.\d)?\d*

Also please find the demo

Sign up to request clarification or add additional context in comments.

4 Comments

+1, but you can simplify it a bit with (?<=\s)[+-]?\d+(?:.\d+)?
Shouldn't you escape the dot?
@TheGuywithTheHat Thank you very much for the improvement.
Thanks a lot! This works pretty perfect for my needs!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.