正则表达式中,用()表示group,而括号内捕获的内容可以供后面使用
但是如果我不想捕获,只不过用()表示纯粹的群组,比如说(abd)+,这里我不想捕获,只是为了表示abdabd而已。怎么办呢?JDK里面有
  Groups beginning with (? are pure, non-capturing groups that do not capture text and do not count towards the group total
   但是没有例子,具体怎么写?
   我实验了(?abc)+,(//?abc)+,(?abc?)+,等,都不行,哪位高手指教一下。

解决方案 »

  1.   

    直接(abc)+不就行了String content = "abcabcxxxabc";
    Pattern patt = Pattern.compile("(abc)+");Matcher match = patt.matcher(content );if (patch.find())
       ....
      

  2.   

    晕,看错题目意思了是你看的不仔细,JDK说的只是(?打头的,问题是关有这个打头是不够的,还需要其他的元素才行的,这样:(?:abc)就行了
      

  3.   

    我也在jdk里面找到了!Special constructs (non-capturing) (?:X) X, as a non-capturing group 
    (?idmsux-idmsux)  Nothing, but turns match flags on - off 
    (?idmsux-idmsux:X)   X, as a non-capturing group with the given flags on - off 
    (?=X) X, via zero-width positive lookahead 
    (?!X) X, via zero-width negative lookahead 
    (?<=X) X, via zero-width positive lookbehind 
    (?<!X) X, via zero-width negative lookbehind 
    (?>X) X, as an independent, non-capturing group 
      

  4.   

    谢谢majy,我试验了一下,果然好用。 
    最后再问一下,象这种JDK上面没有的,在哪里查找呢?
      

  5.   

    ^_^,jdk里面有的,我已经帮你帖出来了!
      

  6.   

    谢谢。我没注意到那里也有关于这个的。只去看group部分了