Sorry this is so specific but I couldn't figure it out from any of the examples I've seen or other questions. I need to find all positive or negative numbers with decimals of any precision in a string. examples: -0.2, .2, 3.4, -3.4, 3.400, 300.5 etc. They must have decimals, no digits and no commas. Any help would be greatly appreciated, I think it should be simple but I'm not getting anywhere.
2 Answers
try this:
/\-?\d*\.\d+/
It will still work for -.2 not sure if you want that.
\-? - or no -
\d* 0 or more digits
\. .
\d+ 1 or more digits
Also if you're sure the entire string will be the value with no other characters, then you should add ^ and $
/^\-?\d*\.\d+$/ would not match something like 'hello1.2' whereas without ^ and $ it would match.
1 Comment
DavidRR
@nschamb1, Since the answer agreco provided worked for you, you should accept his answer and possibly upvote it as well! Also see When should I vote? and How does "Reputation" work?.