tags:

views:

270

answers:

2

Regular expression for negative and positive decimal value so that can be matched with string using pattern and matcher for the correct implementation can any one will provide me with that

A: 

Try this:

[+-]?\d+\.\d+
Rubens Farias
Note that this will fail to recognize patterns like ".4" (no leading zero) or "10" (no decimal). But given the vagueness of the "question," I have no idea if that's a problem or not.
BlairHippo
yeah; since OP said "decimal", I think decimal point is mandatory, but I'm also unsure about that optional integer
Rubens Farias
Well, if we go with the mandatory decimal point, could always do it as "[+-]?\d*\.\d+". Handles the optional leading 0, at least.
BlairHippo
'Decimal' does not mean non-integer. What if OP had said 'binary' or 'octal'? All those qualifiers just limit the range of digits. All such numbers may or may not have a fraction.
gary
You got a point, gary; but if we consider OP accept rate, we'll never know what he meant by decimal.
Rubens Farias
A: 

(\+|-)?([0-9]+(\.[0-9]+))

FreddyB