正则表达示问题

来源:百度知道 编辑:UC知道 时间:2024/06/14 09:07:35
请问如何用正则表达示 表示一个值 是正数(不可以是负数) 长是20 可以有18位整数和2位小数
给分 真给分啊 着急用

\\d{18}[.]\\d{2}
18位数字.2位数字
\\d{19}[.]\\d
19位.1位
\\d{20}
20位

如果你只要18.1这种形式的,用\\d{18}[.]\\d即可
public static void main(String[] args) throws Exception {
String req = "(\\d{18}[.]\\d{2})|(\\d{19}[.]\\d)|(\\d{20})";
String[] test = {"111122223333444455.11", "1111222233334444555.1", "11112222333344445555"};
Pattern p = Pattern.compile(req);
for(String s : test){
System.out.println(s.length());
Matcher m = p.matcher(s);
boolean b = m.matches();
System.out.println(b);
}
}

(([0]{1})|([1-9][\\d]{1,17}?))(\\.\\d{1,2})??

public class Test {
public static void main(String[] args) {
Pattern p = Pattern.compile("(([0]{1})