gstackoverflow gstackoverflow - 5 months ago 13
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 -------^