Java also uses backslashes, so you need to strip backslashes twice, once for a Java string and once for a regular expression.
"([a-zA-Z]:)?(\\\\[a-zA-Z0-9_.-]+)+\\\\?"
Your regular expression matches the literal string [-zA-Z0-9_-] and the literal '?' in the end. I also added a period to allow 'abc.txt'.
However, consider using a different mechanism to determine the correct file names, since there are different schemes (e.g. unix). java.util.File probably throws an exception if the path is invalid, which may be a good alternative, although I don't like to use exceptions for the control flow ...
falstro
source share