Escaping A Regex

no-email (Damien Seguy), Damien Seguy
Tue, 26 Nov 2024 00:00:00 +0000

To use literal characters inside a regex, it is possible to use preg_quote(): it adds a backslash before every special character in the string. Don't forget to use the second argument, which can hold any arbitrary delimiter.
Another option is to use the ``\Q`` and ``\E`` characters inside the regex: it turns all the special characters into a literal value.