I have a java application that needs to validate the format of a String. I am attempting to use Java regular expressions to validate this String. If the String does not follow the pattern then an exception is thrown.
The String needs to follow the following format:
*note the the XXXXs represent a series of any alpha nnumeric or special characters of unspecified length.
I am not sure if my Regular Expression pattern is correct.
Your pattern is matching your invalid string. Did you try printing out the results so you could see what it was doing?
Looks like your square brackets need to be escaped (see below, I added another \ to the pattern and the matching was then as expected). For your information, I didn't check anything about your pattern other than it should match valid and not match invalid test cases.