Only the characters listed on this page need to be escaped in PHP regex matching/replacing.

While < and > can act as delimiter, it doesn't need to be escaped in the given example because you already have /(slash) acting as a delimiter.

Referring to the link in question

The preg_quote() function may be used to escape a string for injection into a pattern and its optional second parameter may be used to specify the delimiter to be escaped.

Answer from hjpotter92 on Stack Overflow
🌐
PHP
php.net › manual › en › function.preg-quote.php
PHP: preg_quote - Manual
To escape characters with special meaning, like: .-[]() and so on, use \Q and \E. For example: <?php echo ( preg_match('/^'.( $myvar = 'te.t' ).'$/i', 'test') ? 'match' : 'nomatch' ); ?> Will result in: match But: <?php echo ( preg_match('/^\Q'.( ...
🌐
SitePoint
sitepoint.com › php
Correct rules for escaping special characters in a preg_match() - PHP - SitePoint Forums | Web Development & Design Community
July 3, 2022 - I am trying to learn how to use preg_match() and already I am having problems understanding the logic. At the moment I am exploring searching for special characters using escapes. I have established that the special characters that need escaping are . \ + * ? [ ^ ] $ ( ) { } = ! | : - All good so far as in if (preg_match("/\?/", $string)) {... But if I search for a \ then I need to escape it with a \\as in if (preg_match("/\\\/", $string)) {... Ok, I can accept that as a special case but...
Discussions

php regex escaping special characters - Stack Overflow
All characters are special in their own way, you know. :) ... Only the characters listed on this page need to be escaped in PHP regex matching/replacing. While < and > can act as delimiter, it doesn't need to be escaped in the given example because you already have /(slash) acting as a delimiter. ... The preg... More on stackoverflow.com
🌐 stackoverflow.com
php - preg_match special characters - Stack Overflow
Define "special characters"... ... Why do you want to use preg_match()? More on stackoverflow.com
🌐 stackoverflow.com
Regex for Special Characters - PHP - SitePoint Forums | Web Development & Design Community
// Check for Special-Character. if (empty($errors)){ if (!preg_match("#[\\~\\`\\!\\@\\#\\$\\%\\^\\&\\*\\(\\)\\_\\-\\+\\=\\{\\}\\[\\]\\|\\:\\;\\ \\.\\?\\/\\\\\\\\]+#", $newPass1)){ $errors['newPass'] = 'Password must have at least 1 Special Character.'; } } 1.) Someone told me I do NOT need to escape ... More on sitepoint.com
🌐 sitepoint.com
0
July 5, 2012
string - PHP preg_match: escaping { and } - Stack Overflow
I am facing a little problem. My string is From {start} to {end} and I want to validate it using preg_match() to avoid illegal chars. ... The point is the escape for { and }. ... If you need to escape characters, just put a backslash (\) before them. Note: if you're using a double quoted string, ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
O'Reilly
oreilly.com › library › view › php-cookbook › 1565926811 › ch13s09.html
13.8. Escaping Special Characters in a Regular Expression - PHP Cookbook [Book]
November 20, 2002 - Use preg_quote( ) to escape Perl-compatible regular-expression metacharacters: $pattern = preg_quote('The Education of H*Y*M*A*N K*A*P*L*A*N').':(\d+)'; if (preg_match("/$pattern/",$book_rank,$matches)) { print "Leo Rosten's book ranked: ...
Authors: David SklarAdam Trachtenberg
Published: 2002
Pages: 640
🌐
Develop Websites
developwebsites.net › home › php › how to match a backslash with preg_match() in php
How to Match A Backslash with preg_match() in PHP
May 5, 2025 - The preg_match() function will ... straightforward as you might first think! In a regular expression a backslash(“\”) is used to escape a special characters so that they will be interpreted literally in the pattern....
🌐
Abareplace
abareplace.com › blog › escape-regexp
Which special characters must be escaped in regular expressions? — Aba Search & Replace
January 8, 2022 - Just like in JavaScript, you also need to escape the delimiter, which is usually /, but you can use another special character such as # or = if the slash appears inside your pattern: if (preg_match('/\/posts\/([0-9]+)/', $path, $matches)) { } // Can be simplified to: if (preg_match('#/post...
🌐
Regular-Expressions.info
regular-expressions.info › php.html
Using Regular Expressions with PHP
When forward slashes are used as the regex delimiter, any forward slashes in the regular expression have to be escaped with a backslash. So https://www\.regexp\.info/ becomes '/https:\/\/www\.regexp\.info\//'. Just like Perl, the preg functions allow any non-alphanumeric character ...
Find elsewhere
🌐
SitePoint
sitepoint.com › php
Regex for Special Characters - PHP - SitePoint Forums | Web Development & Design Community
July 5, 2012 - // Check for Special-Character. if (empty($errors)){ if (!preg_match("#[\\~\\`\\!\\@\\#\\$\\%\\^\\&\\*\\(\\)\\_\\-\\+\\=\\{\\}\\[\\]\\|\\:\\;\\ \\.\\?\\/\\\\\\\\]+#", $newPass1)){ $errors['newPass'] = 'Password must have at least 1 Special Character.'; } } 1.) Someone told me I do NOT need to escape ...
🌐
MetaProgrammingGuide
metaprogrammingguide.com › code › preg-match-special-characters
Php, Preg_match special characters
June 7, 2022 - If the optional input parameter pattern_array is provided, then pattern_array will contain various sections of the subpatterns contained in the search pattern, if applicable. To match a character having special meaning in regex, you need to use a escape sequence prefix with a backslash ( \ ).
🌐
DocStore
docstore.mik.ua › orelly › webprog › pcook › ch13_09.htm
Escaping Special Characters in a Regular Expression (PHP Cookbook)
You want to have characters such as * or + treated as literals, not as metacharacters, inside a regular expression. This is useful when allowing users to type in search strings you want to use inside a regular expression · Use preg_quote( ) to escape Perl-compatible regular-expression ...
🌐
Designcise
designcise.com › web › tutorial › how-to-escape-regular-expression-special-characters-in-php
How to Escape Regex Special Chars in PHP? - Designcise
June 4, 2021 - You can use the backslash character (i.e. \) to escape the regular expression special characters. For example: $str = 'hello?'; $replaceWith = 'hey?'; $pattern = '/hello\?/'; echo preg_replace($pattern, $replaceWith, $str); // 'hey?'
🌐
Reintech
reintech.io › blog › comprehensive-guide-php-preg-quote-function
A Comprehensive Guide to PHP's `preg_quote()` Function
April 14, 2023 - Without preg_quote(), the asterisk in file*.txt would be interpreted as "zero or more of the preceding character," causing unexpected matches. Combine preg_quote() with regex anchors to create precise search patterns: function findWholeWord(string $word, string $text): array { $escapedWord = preg_quote($word, '/'); $pattern = '/\b' .
🌐
O'Reilly
oreilly.com › library › view › php-in-a › 0596100671 › ch15s03.html
15.3. Regexp Special Characters - PHP in a Nutshell [Book]
October 13, 2005 - As mentioned before, $ is a regexp symbol in its own right; however, here we precede it with a backslash, which works as an escape character, turning the $ into a standard character and not a regexp symbol.
Author: Paul Hudson
Published: 2005
Pages: 372