Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular expression for positive and a negative decimal value in java

Tags:

java

regex

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

like image 872
Abhi Avatar asked Jan 15 '10 14:01

Abhi


3 Answers

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

 

like image 70
FreddyBowen Avatar answered Oct 05 '22 23:10

FreddyBowen


Try This! I've also used this way

"^-?[0-9]{1,12}(?:\.[0-9]{1,4})?$"

Rules:

ex: ^-?[0-9]{1,12}(?:\.[0-9]{1,4})?$
^           # Start of string
[0-9]{1,12} # Match 1-12 digits (i. e. 0-999999999999)
(?:         # Try to match...
\.          # a decimal point
[0-9]{1,4}  # followed by one to three digits (i. e. 0-9999)
)?          # ...optionally
$            # End of string
like image 27
RonY Avatar answered Oct 05 '22 23:10

RonY


Try this:

[+-]?\d+\.\d+
like image 31
Rubens Farias Avatar answered Oct 05 '22 22:10

Rubens Farias