rt,我想实现一次性把getYear(xx)+1或getYear(xx)-1通过正则表达式一次性分出来
变为getYear、xx、+、1存到一个字符串数组中……

解决方案 »

  1.   

    replaceall("(",",");
    replaceall(")",",");
    replaceall("+","+,");
    replaceall("-","-,");
    split(",");
    额,这样是不是有点麻烦。。
      

  2.   

    需求中因为有大量类似的字符串还有如
    getDay(xx)+3,getDate(xx)-6,getMonth(xx)+1
    我就是想有没有办法把他们都分开
      

  3.   

    Pattern p = Pattern.compile("[^(,^),^+,^-]+");
    Matcher m = p.matcher("getYear(xx)+1");
    String[] str = new String[10];
    for(int i = 0; m.find(); i ++) {
       str[i] = m.group();
       System.out.println(str[i]);
    }
      

  4.   


    String test = "getDay(xx)+3,getDate(xx)-6,getMonth(xx)+1";
    Matcher m = Pattern.compile("([^,]+?)\\((.*?)\\)(.)(\\d+)").matcher(test);
    while (m.find()) {
    System.out.print(m.group(1) + "  ");
    System.out.print(m.group(2) + "  ");
    System.out.print(m.group(3) + "  ");
    System.out.print(m.group(4) + "  ");
    System.out.println();
    }
    /*
    运行结果:
    getDay  xx  +  3  
    getDate  xx  -  6  
    getMonth  xx  +  1 
    */