if(\"test%$@*)$(%\".matches(\"[^a-zA-Z\\\\.]\")) System.exit(0); if(\"te/st.txt\".matches(\"[^a-zA-Z\\\\.]\")) System.exit(0);
The program
You obtain always false because the matches() method return true only when the pattern matches the full string.
matches()