I have the following regex:
(?!^[&#]*$)^([A-Za-z0-9-'.,&@:?!()$#/\\]*)$
So allow A-Z, a-Z, 0-9, and these special chars '.,&@:?!()$#/\
I want to NOT match if the following set of chars is encountered anywhere in the string in this order:
&#
When I run this regex with just ‘&#’ as input, it does not match my pattern, I get an error, great. When I run the regex with '.,&@:?!()$#/\ABC123 It does match my pattern, no errors.
However when I run it with:
'.,&#@:?!()$#/\ABC123
It does not error either. I’m doing something wrong with the check for the &# sequence.
Can someone tell me what I’ve done wrong, I’m not great with these things.
Borrowing a technique for matching quoted strings, remove
&from your character class, add an alternative for¬ followed by#, and allow the string to optionally end with&: