title: Java file extension regex
body: <p>I'm trying to come up with a Java regex that will match a filename only if it has a valid extension. For example it should match "foo.bar" and "foo.b", but neither "foo." nor "foo".</p>
  
  <p>I've written the following test program</p>
  
  <pre><code>public static void main(String[] args) {
    Pattern fileExtensionPattern = Pattern.compile("\\.\\w+\\z");
  
    boolean one = fileExtensionPattern.matcher("foo.bar").matches();
    boolean two = fileExtensionPattern.matcher("foo.b").matches();
    boolean three = fileExtensionPattern.matcher("foo.").matches();
    boolean four = fileExtensionPattern.matcher("foo").matches();
  
    System.out.println(one + " " + two + " " + three + " " + four);
  }
  </code></pre>
  
  <p>I expect this to print "true true false false", but instead it prints false for all 4 cases. Where am I going wrong?</p>
  
  <p>Cheers,
  Don</p>