简体   繁体   中英

Regular expression for floating point number Java

I want to ask Regular expression

I have aa float number called 0.11,

in this case, the first digit must be Zero

and there can be at most three decimal digits , like 0.1, 0.11, 0.111

In Java, I code like this

String phone_regex = "d{1,1}.d{1,3}";

But it does not work...

Can someone provide some suggestion for me?

thank you

Try escaping your digit character group \\\\d , eg,

"^0\\.\\d{1,3}$"

This matches all strings beginning with a 0 , followed by a dot and 1-3 digits.

^ means beginning of line, $ means end of line. See also java.util.Pattern .

You need to escape the numbers class ( \\d ) and the . char.

String phone_regex = "\\d\\.\\d{1,3}";

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