I’m desperatly searching for a regular expression that match anything between a to z, A to Z, 0 to 9 and “-“. The same regular expression must not match if the string being checked is equal to “admin”.
I tried this :
/^(?!admin)|([-a-z0-9]{1,})$/i
but it doesn’t work, it match for the string admin even if I added the negative lookahead stuff.
I’m using this regex with PHP (PCRE).
Doing “A and not B” in a single regex is tricky. It’s usually better (clearer, easier) to do it in two parts instead. If that isn’t an option, it can be done. You’re on the right track with the negative look-ahead but the alternation is killing you.
In Perl’s extended syntax this is: