public static void retainMatching(Collection<String> values,
      Collection<String> patterns) {
    if (patterns.isEmpty()) return;
    List<String> matches = new ArrayList<String>(values.size());
    for (String p : patterns) {
      Pattern pattern = Pattern.compile(p);
      for (String value : values) {
        if (pattern.matcher(value).matches()) {
          matches.add(value);
        }
      }
    }
    values.retainAll(matches);
  }
public static void retainMatching(Collection<String> values,
      Collection<String> patterns) {
    if (patterns.isEmpty()) return;
    List<String> matches = new ArrayList<String>(values.size());
    for (String p : patterns) {
      Pattern pattern = Pattern.compile(p);
      for (String value : values) {
        if (pattern.matcher(value).matches()) {
          matches.add(value);
        }
      }
    }
    values.retainAll(matches);
  }
public static void retainMatching ( Collection < String > values , Collection < String > patterns ) { if ( patterns . isEmpty ( ) ) return ; List < String > matches = new ArrayList < String > ( values . size ( ) ) ; for ( String p : patterns ) { Pattern pattern = Pattern . compile ( p ) ; for ( String value : values ) { if ( pattern . matcher ( value ) . matches ( ) ) { matches . add ( value ) ; } } } values . retainAll ( matches ) ; }
Retains all values in the subject collection that are matched by
at least one of a collection of regular expressions.
<p>
The semantics of this method are conceptually similar to
{@link Collection#retainAll(Collection)}, but uses pattern matching
instead of exact matching.

@param values subject value collection
@param patterns patterns to match
Retains all values in the subject collection that are matched by at least one of a collection of regular expressions . <p > The semantics of this method are conceptually similar to { @link Collection#retainAll ( Collection ) } but uses pattern matching instead of exact matching .