title: Regex filter for file search Java
body: <p>I'm quite new to using regex so I'm having problems with my current code. I created an Abstract File Search that returns a List of Files. I would like this searcher to be filtered by a regex (have ex. the extension it looks for based on a regex filter).</p>
  <p>The code of my Abstract Searcher:</p>
  <pre><code>public abstract class AbstractFileDiscoverer implements IDiscoverer {
  
      private final Path rootPath;
  
      AbstractFileDiscoverer(final Path rootPath) {
          super();
          this.rootPath = rootPath;
  
      }
  
      protected List&lt;File&gt; findFiles() throws IOException {
          if (!Files.isDirectory(this.rootPath)) {
              throw new IllegalArgumentException(&quot;Path must be a directory&quot;);
          }
  
          List&lt;File&gt; result;
  
          try (Stream&lt;Path&gt; walk = Files.walk(this.rootPath)) {
              result = walk.filter(p -&gt; !Files.isDirectory(p)).map(p -&gt; p.toFile())
                      .filter(f -&gt; f.toString().toLowerCase().endsWith(&quot;&quot;)).collect(Collectors.toList());
          }
          return result;
      }
  
      @Override
      public String getName() {
          // TODO Auto-generated method stub
          return null;
      }
  
  }
  </code></pre>
  <p>I would like the following part to be filtered by the regex, so that only the files that the regex returns as true (for .bat and .sql files) to be collected.</p>
  <pre><code>result = walk.filter(p -&gt; !Files.isDirectory(p)).map(p -&gt; p.toFile())
                      .filter(f -&gt; f.toString().toLowerCase().endsWith(&quot;&quot;)).collect(Collectors.toList());
  </code></pre>
  <p>Could anyone help me achieving it?</p>
  <p>FIRST EDIT:
  I'm aware that <code>toString().toLowerCase().endsWith(&quot;&quot;)</code> always returns true, I actually need the regex there instead of an String with the extension. I forgot to mention that.</p>