code: public static IOFileFilter getRegexFileFilter(String regex) {
          // Inner class defining the RegexFileFilter
          class RegexFileFilter implements IOFileFilter {
              Pattern pattern;
  
              protected RegexFileFilter(String re) {
                  pattern = Pattern.compile(re);
              }
  
              public boolean accept(File pathname) {
                  return pattern.matcher(pathname.getName()).matches();
              }
  
              public boolean accept(File dir, String name) {
                  return accept(new File(dir,name));
              }
          }
  
          return new RegexFileFilter(regex);
      }
docs: Get a @link java.io.FileFilter that filters files based on a regular
  expression.
  
  @param regex the regular expression the files must match.
  @return the newly created filter.