public static final String concatGroups(Matcher matcher){
  StringBuilder b=new StringBuilder();
  final int numGroups=matcher.groupCount();
  for (int i=1; i <= numGroups; i++) {
    String s=matcher.group(i);
    if (s != null) {
      b.append(s);
    }
  }
  return b.toString();
}

public static final String concatGroups ( Matcher matcher ) { StringBuilder b = new StringBuilder ( ) ; final int numGroups = matcher . groupCount ( ) ; for ( int i = 1 ; i <= numGroups ; i ++ ) { String s = matcher . group ( i ) ; if ( s != null ) { b . append ( s ) ; } } return b . toString ( ) ; }
convenience method to take all of the non - null matching groups in a regex matcher and return them as a concatenated string .
