RegexFileFilter (Commons IO 2.5)
Date: 2016-12-01

org.apache.commons.io.filefilter

## Class RegexFileFilter

- java.lang.Object
- - org.apache.commons.io.filefilter.AbstractFileFilter
  - - org.apache.commons.io.filefilter.RegexFileFilter

- All Implemented Interfaces:
    java.io.FileFilter, java.io.FilenameFilter, java.io.Serializable, IOFileFilter

      public class RegexFileFilter
      extends AbstractFileFilter
      implements java.io.Serializable

  Filters files using supplied regular expression(s).

  See java.util.regex.Pattern for regex matching rules

  e.g.

       File dir = new File(".");
       FileFilter fileFilter = new RegexFileFilter("^.*[tT]est(-\\d+)?\\.java$");
       File[] files = dir.listFiles(fileFilter);
       for (int i = 0; i < files.length; i++) {
         System.out.println(files[i]);
       }

  Since:
    1.4
  Version:
    $Id: RegexFileFilter.java 1642757 2014-12-01 21:09:30Z sebb $
  See Also:
    Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `private java.util.regex.Pattern` | `pattern` The regular expression pattern that will be used to match filenames
    `private static long` | `serialVersionUID`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `RegexFileFilter(java.util.regex.Pattern pattern)` Construct a new regular expression filter for a compiled regular expression
    `RegexFileFilter(java.lang.String pattern)` Construct a new regular expression filter.
    `RegexFileFilter(java.lang.String pattern, int flags)` Construct a new regular expression filter with the specified flags.
    `RegexFileFilter(java.lang.String pattern, IOCase caseSensitivity)` Construct a new regular expression filter with the specified flags case sensitivity.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `accept(java.io.File dir, java.lang.String name)` Checks to see if the filename matches one of the regular expressions.

    - ### Methods inherited from class org.apache.commons.io.filefilter.AbstractFileFilter

      `accept, toString`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### serialVersionUID

          private static final long serialVersionUID

      See Also:
        Constant Field Values

    - #### pattern

          private final java.util.regex.Pattern pattern

      The regular expression pattern that will be used to match filenames

  - ### Constructor Detail

    - #### RegexFileFilter

          public RegexFileFilter(java.lang.String pattern)

      Construct a new regular expression filter.
      Parameters:
        `pattern` - regular string expression to match
      Throws:
        `java.lang.IllegalArgumentException` - if the pattern is null

    - #### RegexFileFilter

          public RegexFileFilter(java.lang.String pattern,
                         IOCase caseSensitivity)

      Construct a new regular expression filter with the specified flags case sensitivity.
      Parameters:
        `pattern` - regular string expression to match
        `caseSensitivity` - how to handle case sensitivity, null means case-sensitive
      Throws:
        `java.lang.IllegalArgumentException` - if the pattern is null

    - #### RegexFileFilter

          public RegexFileFilter(java.lang.String pattern,
                         int flags)

      Construct a new regular expression filter with the specified flags.
      Parameters:
        `pattern` - regular string expression to match
        `flags` - pattern flags - e.g. `Pattern.CASE_INSENSITIVE`
      Throws:
        `java.lang.IllegalArgumentException` - if the pattern is null

    - #### RegexFileFilter

          public RegexFileFilter(java.util.regex.Pattern pattern)

      Construct a new regular expression filter for a compiled regular expression
      Parameters:
        `pattern` - regular expression to match
      Throws:
        `java.lang.IllegalArgumentException` - if the pattern is null

  - ### Method Detail

    - #### accept

          public boolean accept(java.io.File dir,
                       java.lang.String name)

      Checks to see if the filename matches one of the regular expressions.
      Specified by:
        `accept` in interface `java.io.FilenameFilter`
      Specified by:
        `accept` in interface `IOFileFilter`
      Overrides:
        `accept` in class `AbstractFileFilter`
      Parameters:
        `dir` - the file directory (ignored)
        `name` - the filename
      Returns:
        true if the filename matches one of the regular expressions

Copyright (c) 2002-2016 Apache Software Foundation