只能数字, 或者是由一个逗号分割的数字例如“22,22”数字位数不限定。
在线等待谢谢

解决方案 »

  1.   

    public void test() {
    String s1 = "111,11233"; //匹配
    String s2 = "111,11,233"; // 不匹配
    String s3 = "111,11233q"; // 不匹配
    String rex = "\\d*,?\\d*";
    Pattern p = Pattern.compile(rex);
    Matcher m = p.matcher(s1);
    if (m.matches())
    System.out.println(m.group());
    }
    怎么不正确了?
      

  2.   

    String s ="aaaaa"; //匹配
      

  3.   

    sorry 我错了,你对。结贴,谢谢!!!
      

  4.   

    [1-9][0-9]{0,2}(,[0-9]{3})*skycncomp(^*-*^为了成为传说中的高手,努力灌水中)的答案是错的
    比如 1,或 ,2 或 012 等
      

  5.   

    我什么地方错误了?
    请指出。
    下面是用你给的做的匹配.
    public void test() {
    String s1 = "1,"; //匹配
    String s2 = ",2"; // 匹配
    String s3 = "012"; // 匹配
    String rex = "\\d*,?\\d*";
    Pattern p = Pattern.compile(rex);
    Matcher m = p.matcher(s3);
    if (m.matches())
    System.out.println(m.group());
    }