I got this issue figuring out how to build a regexp for verifying a netbios name. According to the ms standard these characters are illegal \/:*?"<>|
So, thats what I'm trying to detect. My regex is looking like this
^[\\\/:\*\?"\<\>\|]$
But, that wont work.
Can anyone point me in the right direction? (not regexlib.com please...) And if it matters, I'm using php with preg_match.
Thanks
Your regular expression has two problems:
[]
), you only need to quote characters that are special within character classes, i.e. hyphen, square bracket, backslash.The following call works for me:
preg_match('/[\\/:*?"<>|]/', "foo"); /* gives 0: does not include invalid characters */
preg_match('/[\\/:*?"<>|]/', "f<oo"); /* gives 1: does include invalid characters */