Reputation:
I need a (Java) regular expression that will match:
XXXX.X
Where X is any number, only one number after the decimal point.
Upvotes: 5
Views: 21813
Reputation: 386
If the number is exactly 4 digits,then try this
"/(^([0-9]{4})[.]([0-9]{1})$)/"
Eg : 1234.4
Or if the number is of unlimited digits,try this..
"/(^([0-9]{0,})[.]([0-9]{1})$)/"
Eg: 1234.4
45.8
589745324744.7
Upvotes: 0
Reputation: 208435
Try ^\d{4}\.\d$
if you want the entire string to match, remove the ^
and/or $
if you want it to find matches within a larger string.
If there can be any number of integers before the .
use \d+
instead of \d{4}
to match one or more, or \d*
to match zero or more (the string ".5"
would match \d*\.\d
).
Upvotes: 13