开发者

How to use ^/$ if it's already used as a delimiter for regex in PHP?

开发者 https://www.devze.com 2022-12-23 05:42 出处:网络
$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 ch
$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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号