To determine if the filename contains a resolution:
if (myFilePathString.matches(".*/\\d{3,4}x\\d{3,4}.*")) {
// image filename contains a resolution
}
To extract the resolution in just one line:
String resolution = myFilePathString.replaceAll(".*/(\\d{3,4}x\\d{3,4}).*", "$1");
Note that the extracted resolution will be blank (not null
) if there is no resolution in the filename, so you could extract it, then test for blank:
String resolution = myFilePathString.replaceAll(".*/(\\d{3,4}x\\d{3,4}).*", "$1");
if (!resolution.isEmpty()) {
// image filename contains a resolution
}