"(.*?)(\\([^()]+\\))(.*)"     什么意思 看不懂? 谁能看懂并且说明白,感谢

解决方案 »

  1.   


    public static void main(String[] args) {
    String pattern = "(.*?)(\\([^()]+\\))(.*)";
    /*
     * (.*?):任意多个字符开头,优先匹配0个
     * 
     * \\([^()]+\\):左括弧  后面是  不是括弧的任意多个字符,至少一个, 后面是 右括弧
     * 
     * (.*):任意对个字符,优先匹配多个
     * 
     * */
    String str = "a*(b/(c+d))";
    Matcher m = Pattern.compile(pattern).matcher(str);
    while(m.find()){
    System.out.println(m.group(2));//可以匹配出(***)这样的子串
    }
    }