Find a template file

I am trying to find a file with a name like: ENV20120517, all you need and finish with .DAT

So, I am installing the template for: "ENV20120517 *. * DAT".

 public boolean accept(File dir, String name) {
    if (pattern != null) {
        return name.matches(pattern);
    }
    return false;
 }

Why with the previous template do I believe for: name = "ENV20120516053518.DAT"?

+3
source share
3 answers

String.matches()accepts a regular expression , not a ball pattern .

It just so happens to be ENV20120517*.*DATa valid regular expression. However, this has a different meaning for the expected one: it matches any line starting with ENV2012051and ending with DAT( .*matches anything, but 7*op).

ENV20120517.*[.].*DAT

, glob Java, . java.util.regex " glob " ?

+4

Parttern "ENV20120517.*DAT", "ENV20120517*.*DAT", * 0 7 char, "ENV20120516053518.DAT".matches("ENV20120517*.*DAT") - true.

0

Try

pattern = "ENV20120517.*\\.DAT"

Or more strictly:

pattern = "^ENV20120517.*\\.DAT$"
0
source

All Articles