Created
January 6, 2015 16:14
-
-
Save tferr/acdea550e56ce9baadd4 to your computer and use it in GitHub Desktop.
Validate file extensions using regex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.regex.Matcher; | |
import java.util.regex.Pattern; | |
boolean validFile(String filename) { | |
String FILE_PATTERN = "(.*(\\.(?i)(stk|tif))$)"; | |
Pattern pattern = Pattern.compile(FILE_PATTERN); | |
Matcher matcher = pattern.matcher(filename); | |
return matcher.matches(); | |
} | |
System.out.println(""+validFile("path/to/ a file.bmp")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment