Wondering if someone can tell me why this regular expression doesn’t work.
Expression -> ^[A-Za-z0-9$&!#-_?:;\"']+$
The problem is, it’s matching against characters not in the set. For example, the word match properly matches and the word match~ does not, but match@ and match! incorrectly match.
I’m using java to match it, and the matching should be fairly straight forward with the code below:
RE re = new RE(expression);
return re.match(value);
I know it’s probably something ridiculously simple that I’m missing, but if anyone has any thoughts on it, I’d greatly appreciate it!
The problem is the hyphen
-in your character set. Your are accepting characters from # to _.Change it to
^[-A-Za-z0-9$&!#_?:;\"']+$or escape-.