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.
Introdução
A sintaxe para padrões usados nestas funções assemelham-se com Perl. A expressão precisa estar incluída entre delimitadores, uma barra (/), por exemplo. Qualquer caractere pode ser usado para delimitar desde que não seja alfanumérico ou backslash (\). Se o caractere delimitador tem de ser usado na própria expressão, ele necessitará de escape. Desde o PHP 4.0.4, você pode também usar delimitadores Perl-style (), {}, [], e <>. Veja Sintaxe do Padrão para mais detalhes.
No final do delimitador pode ser seguido por vários modificadores que afetam a combinação. Veja Modificadores do Padrão.
PHP também suporta expressões regulares usando a sintaxe POSIX-extendido utilizando as funções para regex no padrão POSIX-extendido.
Nota: Esta extensão mantém uma global por thread cache da expressão regular compilada.
Você precisa estar ciente de algumas limitações da PCRE. Leia » http://www.pcre.org/pcre.txt para mais informações.
Introdução
12-Oct-2009 10:22
12-Aug-2009 12:51
php supports posix regular expressions, but only in the short term.
pcre seems capable of most things posix regex does
One point of difference is that PCRE requires you delimit your regex, that is: start and end it with a character that is not used elsewhere in the regex,
this provides a space after the ending delimiter to put option characters.
