tags:

views:

44

answers:

2
$regex = '$....$'

$regex = '^...^'

In the above two cases,how to use ^/$ to match the beginning/end of a string?

+2  A: 

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 /:

'~^/$~'
Gumbo
Bingo. Just use a different delimiter. I like @.
ceejayoz
So it's impossible to use `$` both for delimiter and reserve its meaning for regex?
That's what happens when you use a special character as your delimiter. Why are you wedded to a specific one?
ceejayoz
A: 

just do escaping ?

$str='^...^';
preg_match("/^\^.*\^$/",$str,$matches);
print_r($matches);
ghostdog74
You didn't use `^/$` as delimiter