I use this pretty simple regular expression:
^[\x20-\x7E]+$
When I try to use it with some of PHP regex functions, such as preg_match() it throws warning in sole case when I use ~
character (tilde) as delimiter.
So, execution of following lines goes well
preg_match("/^[\x20-\x7E]+$/", $s); # delimiter "/"
preg_match("!^[\x20-\x7E]+$!", $s); # delimiter "!"
preg_match("#^[\x20-\x7E]+$#", $s); # delimiter "#"
but for some reason, this line
preg_match("~^[\x20-\x7E]+$~", $s); # delimiter "~"
throws a warning
Warning: preg_match(): Unknown modifier ']' in some_script.php on line XX
note: it happens only when it's used with double-quotes!
I'm using tilde all the time as delimiter and never faced problems with it until this case and really wonder why that happens. Can't find does tilde have some special meaning in regular expressions (i'm 99% now sure it does not), or it's just a bug.
I can certainly work around this, but the question is: What's the difference between tilde and any other delimiter?