Use the functions in PHP's PCRE extension to work with regular expressions in your programs. These functions allow you to match a string against a pattern and to alter a string based on how it matches a pattern. When you pass a pattern to one of the PCRE functions, it must be enclosed in delimiters. Traditionally, the delimiters are slashes, but you can use any character that's not a letter, number, or backslash as a delimiter. If the character you choose as a delimiter appears in the pattern, it must be backslash-escaped in the pattern, so you should only use a nonslash delimiter when a slash is in your pattern.
After the closing delimiter, you can add one or more pattern modifiers to change how the pattern is
interpreted. These modifiers are listed at http://www.php.net/pcre.pattern.modifiers. One handy modifier is
, which makes the pattern matching case-insensitive.
For example, the patterns (with delimiters)
/[a-z]+/i produce the same
Another useful modifier is
s, which makes the dot metacharacter match newlines.
The pattern (with delimiters)
@<b>.*?</b>@ matches a set of
<b></b> tags and the text between them, but only if that text
is all on one line. To match text that may include newlines, use the
function tests whether a string matches a
pattern. Pass it the pattern and the string to test as arguments. It returns
1 if the string matches the pattern and
0 if it doesn't. Example ...