Skip to content

Instantly share code, notes, and snippets.

@tferr
Created January 6, 2015 16:14
Show Gist options
  • Save tferr/acdea550e56ce9baadd4 to your computer and use it in GitHub Desktop.
Save tferr/acdea550e56ce9baadd4 to your computer and use it in GitHub Desktop.
Validate file extensions using regex
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