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...
🌐
BrainBell
brainbell.com › php › escaping-special-characters-in-regular-expressions.html
Escaping special characters in regular expressions in PHP – BrainBell
Escaping the special meaning of a character is done with the backslash character as with the expression "2\+3", which matches the string "2+3". If the + isn’t escaped, the pattern matches one or many occurrences of the character 2 followed by the character 3. ... <?php $string = 'Hi, 2+3 ...
🌐
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
🌐
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 ...
🌐
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
🌐
SitePoint
sitepoint.com › php
Regex for Special Characters - PHP - SitePoint Forums | Web Development & Design Community
July 5, 2012 - I have some questions about the Regex below… // Check for Special-Character. if (empty($errors)){ if (!preg_match("#[\\~\\`\\!\\@\\#\\$\\%\\^\\&\\*\\(\\)\\_\\-\\+\\=\\{\\}\\[\\]\\|\\:\\;\\&lt;\\&gt;\\.\\?\\/\\\\\\\…
Find elsewhere
🌐
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 - Develop Websites Learn HTML, ... 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....
🌐
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?'
🌐
Stack Overflow
stackoverflow.com › questions › 71054982 › word-with-special-characters-match-via-preg-match-in-php
regex - Word with special characters match via preg_match in php - Stack Overflow
February 9, 2022 - (?!\B\w) - checks if the next char ... not required. Note the preg_quote($model, '/') part: it escapes all special chars in the $model string and also the / char that is used as a regex delimiter char....
🌐
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 ...
🌐
GeeksforGeeks
geeksforgeeks.org › php › function-to-escape-regex-patterns-before-applied-in-php
Function to escape regex patterns before applied in PHP - GeeksforGeeks
July 12, 2025 - <?php // Create a string which need to be escaped $str = "Welcome to GfG! (+ The course fee. $400) /"; echo "Before Processing - " . $str . PHP_EOL; // Use preg_quote() on above string $processedStr = preg_quote($str); // Display the output echo "After Processing - " . $processedStr; ?> ... Before Processing - Welcome to GfG! (+ The course fee. $400) / After Processing - Welcome to GfG\! \(\+ The course fee\. \$400\) / Notice that a backslash was put in front of every special character, but not for the forward slash.