Regular Expressions
A Regex is typically created with a regex literal using PCRE syntax. It consists of a string of UTF-8 characters enclosed in forward slashes ():
The delimiter character /
must be escaped inside slash-delimited regular expression literals. Note that special characters of the PCRE syntax need to be escaped if they are intended as literal characters.
The closing delimiter may be followed by a number of optional modifiers to adjust the matching behaviour of the regular expression.
i
: case-insensitive matching (PCRE_CASELESS
): Unicode letters in the pattern match both upper and lower case letters in the subject string.x
: extended whitespace matching (PCRE_EXTENDED
): Most white space characters in the pattern are totally ignored except when ignore or inside a character class. Unescaped hash characters denote the start of a comment ranging to the end of the line.
These are handy to write regular expressions that include slashes which would have to be escaped in slash-delimited literals.