I haven't used regular expressions till now, but I need a regex that matches a string representing a positive or negative numeric value like
234
-8
3.346
-564.4
It should NOT match any text or mixtures of characters (<>#?_...), numbers and text like
abc
.-.
<11.45
amount111.43
345.654.33
This should do it:
^-?\d+(\.\d+)?$
^
start of string
-?
minus sign one or zero times
\d+
digits, one or more
(\.\d+)?
a dot following by one or more digits, this whole block one or zero times
$
end of string
Also take note of Utkanos comment for your next question on SO :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With