Writing a simple regex, but I've never been so good at it.
What I'm trying to do is check the string (file name) to make sure it contains only az, AZ, 0-9 or special underscores (_) for period (.) Or dash (-).
That's what i
if(filename.length() < 1 || !filename.matches("^[a-zA-Z0-9[.][_][-]]+"))
return false;
else
return true;
It seems to work, but for me it does not look very elegant. Is there a better / more readable way to write this?
Thanks in advance! Just try to learn how to write these finders better.
-Will be
source
share