code: public static final String concatGroups(MatcherCompat 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();
      }
docs: Convenience method to take all of the non-null matching groups in a
  regex Matcher and return them as a concatenated string.
  
  @param matcher      The Matcher object from which grouped text will
  be extracted
  
  @return             A String comprising all of the non-null matched
  groups concatenated together