Java regex for XLSX file extension -
i have following file name:
abc 14-15 pcee qwerty checklist - checked xyz idffcfyyl-01 bb.xlsx
i using following regex test whether file has xlsx
extension:
string filename = "abc 14-15 pcee qwerty checklist - checked xyz idffcfyyl-01 bb.xlsx"; private static final string checkxlsxfile = "([^\\s]+(\\.(?i)(xlsx))$)"; private static final pattern pattern = pattern.compile(checkxlsxfile); if (pattern.matcher(filename).matches()) { system.out.println("heaven"); } else { system.out.println("hell"); }
however, pattern fails file name. can me resolve this?
why not use string.endswith(string) method?
if(filename.tolowercase().endswith(".xlsx")) { // } else { // else }
Comments
Post a Comment