How to use ^/$ if it's already used as a delimiter for regex in PHP?
$regex = '$....$'
$regex = '^...^'
In开发者_JAVA技巧 the above two cases,how to use ^/$
to match the beginning/end of a string?
You can use any non-alphanumeric, non-backslash, non-whitespace character as delimiter. But you shouldn’t use characters that have a special meaning in regular expressions.
So you could use the ~
if you don’t want to use /
:
'~^/$~'
just do escaping ?
$str='^...^';
preg_match("/^\^.*\^$/",$str,$matches);
print_r($matches);
精彩评论