Introduction

The syntax for patterns used in these functions closely resembles Perl. The expression must be enclosed in the delimiters, a forward slash (/), for example. Delimiters can be any non-alphanumeric, non-whitespace ASCII character except the backslash (\) and the null byte. If the delimiter character has to be used in the expression itself, it needs to be escaped by backslash. Since PHP 4.0.4, you can also use Perl-style (), {}, [], and <> matching delimiters. See Pattern Syntax for detailed explanation.

The ending delimiter may be followed by various modifiers that affect the matching. See Pattern Modifiers.

PHP also supports regular expressions using a POSIX-extended syntax using the POSIX-extended regex functions.

Note:

This extension maintains a global per-thread cache of compiled regular expressions (up to 4096).

Warning

You should be aware of some limitations of PCRE. Read » http://www.pcre.org/pcre.txt for more info.

The PCRE library is a set of functions that implement regular expression pattern matching using the same syntax and semantics as Perl 5, with just a few differences (see below). The current implementation corresponds to Perl 5.005.

Коментарии

Converting POSIX regex patters to PCRE is non-trivial. I had many (about 17.000) patterns stored in a DB, and found that surrounding one with delimiters (such as '/'), after quoting them, is not enough.

I've been biten by a \r that slipped into a pattern (that was supposed to be \.r and became .\r instead). Too bad in PCRE it stands for carriage-return.

AFAIK, there's no way to disable this behaviour and make PCRE more POSIX compatibile. You have to look for every single escape sequence that has no meaning in POSIX regex but has one in PCRE and remove the backslash.

Before POSIX regex are removed it would be really cool to have a function that converts a POSIX regex pattern into the equivalent PCRE one.
2009-10-12 06:22:58
http://php5.kiev.ua/manual/ru/intro.pcre.html

    Поддержать сайт на родительском проекте КГБ