if (Pattern.matches("[^a-zA-z0-9]", args[0])) System.out.println("Invalid");
Where args[0] is 12AS08Z/Andrei
Level 41
Why is the codeline below not printing what I say when the condition is true?
Resolved
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
Guadalupe Gagnon
7 June 2021, 13:58solution
That would only match a String of one character that is not a letter of a number. Examples of Strings that would be true in that case and print "Invalid":
"%"
"!"
"$"
Examples of Strings that would be false and not print that:
"%%"
"!!"
"$$"
(any String that had a length of zero or a length of 2 or more)
+2
Andrei
8 June 2021, 07:07
OK, so I need to look for a different way to format the regex. Thanks!
0