List files with two dots in their names using java regular expressions
- by Nivas
I was trying to match files in a directory that had two dots in their name, something like theme.default.properties
I thought the pattern .\\..\\.. should be the required pattern [. matches any character and \. matches a dot] but it matches both oneTwo.txt and theme.default.properties
I tried the following:
[resources/themes has two files oneTwo.txt and theme.default.properties]
1.
public static void loadThemes()
{
File themeDirectory = new File("resources/themes");
if(themeDirectory.exists())
{
File[] themeFiles = themeDirectory.listFiles();
for(File themeFile : themeFiles)
{
if(themeFile.getName().matches(".\\..\\.."));
{
System.out.println(themeFile.getName());
}
}
}
}
This prints nothing
and the following
File[] themeFiles = themeDirectory.listFiles(new FilenameFilter()
{
public boolean accept(File dir, String name)
{
return name.matches(".\\..\\..");
}
});
for (File file : themeFiles)
{
System.out.println(file.getName());
}
prints both
oneTwo.txt
theme.default.properties
I am unable to find why these two give different results and which pattern I should be using to match two dots...
Can someone help?