开发者

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);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜