private static void filterTablesByRegex(final Collection<TableDescriptor> descriptors,
    final Pattern pattern) {
    final String defaultNS = NamespaceDescriptor.DEFAULT_NAMESPACE_NAME_STR;
    Iterator<TableDescriptor> itr = descriptors.iterator();
    while (itr.hasNext()) {
      TableDescriptor htd = itr.next();
      String tableName = htd.getTableName().getNameAsString();
      boolean matched = pattern.matcher(tableName).matches();
      if (!matched && htd.getTableName().getNamespaceAsString().equals(defaultNS)) {
        matched = pattern.matcher(defaultNS + TableName.NAMESPACE_DELIM + tableName).matches();
      }
      if (!matched) {
        itr.remove();
      }
    }
  }
Removes the table descriptors that don't match the pattern.
@param descriptors list of table descriptors to filter
@param pattern     the regex to use
hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java