$regex = \'$....$\'
$regex = \'^...^\'
In 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);