omfg.. i had that, i tried that 1000 times.. but i had put the brackets on the end.. like this "/^[a-zA-Z0-9_-\[\]]+$/" that's why it was working..
Thank you very much! Solved!
g1smd
7:40 pm on Sep 11, 2011 (gmt 0)
It should also work with the brackets at the very end.
I moved them merely to show more clearly the required escaping. The \[\]] format makes my eyes boggle and \[\]_-] is more clear.
Also, some RegEx parsers like the hyphen to be the very last item in the list otherwise they get confused.
lucy24
8:57 pm on Sep 11, 2011 (gmt 0)
Also, some RegEx parsers like the hyphen to be the very last item in the list otherwise they get confused.
... while others will only recognize it as a literal hyphen if it's the first item in the list ;) Literal carets, otoh, can't come first unless they are escaped. (I only know this because I've got a RegEx reference page open from another thread. Fortunately, grouping brackets tend not to get upset if you follow the "when in doubt, escape it" principle.)
rocknbil
4:17 pm on Sep 12, 2011 (gmt 0)
Since no one's mentioned why, square brackets designate a character class. when you want to match bracket within character class, this is why it needs to be escaped.