When working with regular expressions (regex) in PHP, it is quite common to use a forward slash (a.k.a. "slash) as delimiter for a regex pattern.
$match = preg_match('/abc/', $subject);However, when the pattern is a path URL with a path, when a slash / is used as regex delimiter, slashes in the string need to be escaped.
This makes the text harder to parse for humans.
$match = preg_match('/http:\/\/example.com\/api/', $subject);If another delimiter is used,1 the slash no longer needs to be escaped:
$match = preg_match('#http://example.com/api#', $subject);This also makes it more clear whether any trailing slash is a delimiter or part of the match pattern.
Footnotes
-
β©Often used delimiters are forward slashes (/), hash signs (#) and tildes (~).