class RegExTest
{
public static void main( String args[] )
{
String[] fileNames = { “file.txt”, “file.xml”, “file-name.txt”, “file_name.txt”, “file.name.txt”,
“file name.txt”, “file.abc”, “file.tmp”, “filetxt.abc”, “file.txt.abc”, “xml”, “.xml”, };
Pattern pattern = Pattern.compile( “.+\\.(?i)(txt|xml)$” );
Arrays.stream( fileNames ).forEach( fileName ->
{
Matcher matcher = pattern.matcher( fileName );
System.out.println( fileName + ” – ” + matcher.matches() );
} );
}
}