简体   繁体   中英

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 decimal 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM