0

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.

1
  • I'm drawing a blank but nothing like 5, -1, 100 Commented Sep 3, 2012 at 2:16

2 Answers 2

1

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.

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

1 Comment

@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?.
0

try this one,I just test it in regex coach,fits your example:

"[^\d]\.\d+|[-|\d+|-\d+]\d*\.\d+|\.d+"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.