Escaping A Regex¶
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.