gstackoverflow gstackoverflow - 2 months ago 5x
Java Question

Check that String is alphanumeric with length 1 to 5

I have wrote the following test code snippet:


However, it returns

Why and how to fix this?


You're escaping the first square bracket with the \\, which means the expression between the square brackets isn't treated as a character class. Remove the escaping and you should be OK:

// Here -------^