To determine if a file name contains permission:
if (myFilePathString.matches(".*/\\d{3,4}x\\d{3,4}.*")) {
To extract permission in only one line:
String resolution = myFilePathString.replaceAll(".*/(\\d{3,4}x\\d{3,4}).*", "$1");
Note that the extracted permission will be empty (not null ) if there is no permission in the file name, so you can extract it and then check for a space:
String resolution = myFilePathString.replaceAll(".*/(\\d{3,4}x\\d{3,4}).*", "$1"); if (!resolution.isEmpty()) {
source share