Requirement: A string must contain only letters, numbers and a space.
I have to pass the clean name to another API.
Implementation: Java
I came up with this for my requirement
public static String getCleanFilename (String filename) {
if (filename == null) {
return null;
}
return filename.replaceAll ("[^ A-Za-z0-9]", "");
}
This works well for several of my test systems, but I want to know if there are not enough boundary conditions or some better way (in performance) to do this.
source
share