public class RegexFileFilter extends Object implements FileFilter, Serializable
See java.util.regex.Pattern for regex matching rules.
For example, to retrieve and print all java files where the name matched the regular expression in the current directory:
FileSystemManager fsManager = VFS.getManager(); FileObject dir = fsManager.toFileObject(new File(".")); FileObject[] files = dir.findFiles(new FileFilterSelector(new RegexFileFilter("ˆ.*[tT]est(-\\d+)?\\.java$"))); for (int i = 0; i < files.length; i++) { System.out.println(files[i]); }
Modifier and Type | Field and Description |
---|---|
static String |
PATTERN_IS_MISSING
Exception message when no pattern is given in the constructor.
|
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(FileSelectInfo fileSelectInfo)
Checks to see if the file name matches one of the regular expressions.
|
public static final String PATTERN_IS_MISSING
public RegexFileFilter(Pattern pattern)
pattern
- regular expression to match - Cannot be nullpublic RegexFileFilter(String pattern)
pattern
- regular string expression to match - Cannot be nullpublic RegexFileFilter(String pattern, int flags)
pattern
- regular string expression to matchflags
- pattern flags - e.g. Pattern.CASE_INSENSITIVE
public RegexFileFilter(String pattern, IOCase caseSensitivity)
pattern
- regular string expression to match - Cannot be nullcaseSensitivity
- how to handle case sensitivity, null means
case-sensitivepublic boolean accept(FileSelectInfo fileSelectInfo)
accept
in interface FileFilter
fileSelectInfo
- the File to checkCopyright © 2002–2020 The Apache Software Foundation. All rights reserved.