downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

インストール/設定> <PCRE
Last updated: Fri, 13 Nov 2009

view this page in

導入

この正規表現関数で使用するパターンの構文は、Perl と類似しています。 正規表現は、スラッシュ (/) などのデリミタで囲う必要があります。 デリミタには使用できるのは、非英数字、非空白文字の任意の ASCII 文字ですが、バックスラッシュ (\) と null バイトは使用できません。 デリミタ文字を正規表現本体において使用する必要がある場合は、 バックスラッシュでエスケープします。PHP 4.0.4 以降、 Perl形式の (), {}, [], <> も使用可能です。 パターンの詳細については、パターン構文 を参照してください。

様々な修飾子を終端デリミタの後に付け、 マッチングに変化を与えることができます。 パターン修飾子 を参照ください。

PHP は、POSIX 拡張正規表現関数 において、 POSIX 拡張構文を用いた正規表現もサポートしています。

注意: この拡張モジュールでは、コンパイルした正規表現のために スレッド単位のグローバルキャッシュ (最大 4096) を管理しています。

警告

PCRE には、いくつかの制限があります。詳細は、» http://www.pcre.org/pcre.txt を参照してください。

PCRE ライブラリは、Perl 5 と同じ文法構文を用いた 正規表現パターンマッチ処理を実装した関数群ですが、多少異なる点もあります (以下を参照ください)。現在の実装は Perl 5.005 に対応しています。



add a note add a note User Contributed Notes
導入
m dot colombo at NOSPAM dot esi dot it
12-Oct-2009 10:22
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.
Anonymous
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.

インストール/設定> <PCRE
Last updated: Fri, 13 Nov 2009
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites