If you have to identify / find files in one directory based on many different regular expression patterns in a file name, the below class might be of interest for you.
It is implementing the Java interface FilenameFilter in combination with the classes regex.Matcher and regex.Pattern to create a new class called FilenamePattern. I am usually not praising myself but I like the name of this class.
In its current version the FilenamePattern has an acceptable performance for a few patterns, which file names should be compared against.
If you however intend to use it to search for many patterns in file names in one or more directories, I suggest to compile all Pattern objects at initialization time and hold them in a separate collection. In the below version the patterns are compiled for each handed file in a handed directory. This is of course inefficient.
For the sake of simplicity one could argue that it would be easier to use methods offered by the class String in order to match file names against Strings. For example the method "matches" accepts regex patterns. However it might be a bit easier to use, they will also have to compile a pattern every time this method is called if it is not automatically cached by Java. With below solution you at least have the freedom to cache Patterns and a FilenameFilter is easy to use.
Version & Remarks
This version is now expected to be faster than the first version 0.1. I changed the initialization of the class in order to compile handed regular expressions into Patterns only once instead of compiling it for each tested file in a directory. Also logging has been added in order to allow more detailed feedback to calling methods.
Below source code serves as an example for how regular expressions can be incorporated into an implementation of the interface FilenaemFilter.
Referenced Java classes
Links to important referenced classes can be found below.