开发者

What regex will match 4 digits, a period, then one and only one digit?

开发者 https://www.devze.com 2023-01-31 16:11 出处:网络
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,

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

0

精彩评论

暂无评论...
验证码 换一张
取 消