When using the PCRE function, the pattern needs to be enclosed by delimiters. The delimiter can be any non-alphanumeric, non-backslash, or non-whitespace character.
Commonly used delimiters are forward slash (/), hash symbol (#) and negation symbol (~). The following examples are all patterns using legal delimiters.
/foo bar/ #^[^0-9]$# +php+ %[a-zA-Z0-9_-]%
If a delimiter needs to be matched within a pattern, it must be escaped with a backslash. If delimiters occur frequently within the pattern, a better option is to use other delimiters to improve readability.
/http:\/\// #http://#
When you need to put a string into a pattern for use, you can use the preg_quote() function to escape it. Its second parameter (optional) can be used to specify the delimiter that needs to be escaped.
In addition to the delimiters mentioned above, you can also use bracket-style delimiters. The left bracket and the right bracket serve as the start and end delimiters respectively.
{this is a pattern}
You can add pattern modifiers after the closing delimiter. The following example is a case-insensitive match:
#[a-z]#i