What regex will match 4 digits, a period, then one and only one digit?
I need a (Java) regular expression that will match:
XXXX.X
Where X is any number, only one number after the dec开发者_如何转开发imal point.
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
).
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
精彩评论