Regex encapsulation php
The only thing that matters for PHP / PCRE is that you must use the same character at the beginning and at the end .
It's important for you to avoid: inside a regex, you need to escape the delimiter if you want to use it.
For example, to match a portion of a URL using / as a delimiter, a regex might look like this:
'/^http:\/\/www/'
When using /
as a separator, you need to escape the forward slashes inside the regex - not easy and doesn't look good.
On the other hand, using #
as a separator:
'#http://www#'
Much easier to write and read, isn't it?
Depending on your needs and / or preference, you can use any character you want - sometimes I see " !
" or " ~
", for example.
source to share