public class RegexFileFilter extends AbstractFileFilter implements Serializable
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]); }
Constructor and Description |
---|
RegexFileFilter(Pattern pattern)
Construct a new regular expression filter for a compiled regular expression
|
RegexFileFilter(String pattern)
Construct a new regular expression filter.
|
RegexFileFilter(String pattern,
int flags)
Construct a new regular expression filter with the specified flags.
|
RegexFileFilter(String pattern,
IOCase caseSensitivity)
Construct a new regular expression filter with the specified flags case sensitivity.
|
Modifier and Type | Method and Description |
---|---|
boolean |
accept(File dir,
String name)
Checks to see if the filename matches one of the regular expressions.
|
accept, toString
public RegexFileFilter(String pattern)
pattern
- regular string expression to matchIllegalArgumentException
- if the pattern is nullpublic RegexFileFilter(String pattern, IOCase caseSensitivity)
pattern
- regular string expression to matchcaseSensitivity
- how to handle case sensitivity, null means case-sensitiveIllegalArgumentException
- if the pattern is nullpublic RegexFileFilter(String pattern, int flags)
pattern
- regular string expression to matchflags
- pattern flags - e.g. Pattern.CASE_INSENSITIVE
IllegalArgumentException
- if the pattern is nullpublic RegexFileFilter(Pattern pattern)
pattern
- regular expression to matchIllegalArgumentException
- if the pattern is nullpublic boolean accept(File dir, String name)
accept
in interface FilenameFilter
accept
in interface IOFileFilter
accept
in class AbstractFileFilter
dir
- the file directory (ignored)name
- the filenameCopyright © 2002–2017 The Apache Software Foundation. All rights reserved.