コンテンツにスキップ

利用者:Meniv/sandbox/PCRE

Perl Compatible Regular Expressions
開発元 Philip Hazel
最新版
8.33 / 2013年5月28日 (11年前) (2013-05-28)
プログラミング
言語
C言語
プラットフォーム クロスプラットフォーム
種別 パターンマッチングライブラリ
ライセンス BSDライセンス
公式サイト http://www.pcre.org/
テンプレートを表示

PCRE (Perl Compatible Regular Expressions) は、Perl5 互換の正規表現C言語で実装したライブラリである。BSDライセンスで配布されている[1]。 元は、メール転送エージェントであるEximのために書かれたものであったが[2]、現在では、Apache[3]Postfix[4]、Nmap[4]Safari[5]Maildrop[6]などをはじめとした多数のソフトウェアに組み込まれている[2]

機能[編集]

  1. PCRE has developed an extensive and in some ways unique feature set. While it originally aimed at feature-equivalence with Perl, over time a number of features have been first implemented in PCRE and only much later added to Perl. During the PCRE 7.x and Perl 5.9.x (development track) phase the two projects have coordinated development and are to the extent possible feature equivalent. In some cases PCRE has included in mainline releases features that originated with Perl 5.9.x and in some cases Perl 5.9.x has included features that were previously only available in PCRE.[7]
  1. PCRE has developed an extensive and in some ways unique feature set.

当初はPerlと同等の機能を実装しようと開発されたが、後にさまざまな機能がPCREに実装されるようになりのちにPerl本体に実装される形になっていった。PCRE 7.x系とPerl 5.9.xはthe two projects have coordinated development and are to the extent possible feature equivalent. In some cases PCRE has included in mainline releases features that originated with Perl 5.9.x and in some cases Perl 5.9.x has included features that were previously only available in PCRE.

While it originally aimed at feature-equivalence with Perl, over time a number of features have been first implemented in PCRE and only much later added to Perl. During the PCRE 7.x and Perl 5.9.x (development track) phase the two projects have coordinated development and are to the extent possible feature equivalent. In some cases PCRE has included in mainline releases features that originated with Perl 5.9.x and in some cases Perl 5.9.x has included features that were previously only available in PCRE.

  1. PCRE includes the following features:

PCREが実装している機能を以下に示す。

  • 実行時コンパイラのサポート
  • 一貫性のあるエスケープルール
  • 文字クラスの拡張
  • 最短マッチ(「貪欲でない」とも呼ばれます)
  • Unicode文字用のプロパティ
  • 複数行マッチング
  • 改行文字を選択するオプション
  • \Rオプション
  • パターン開始のオプション
  • 名前付きキャプチャ
  • 後方参照
  • サブルーチン
  • 先読み、戻り読み
  • ゼロ幅のエスケープシーケンス
  • コメント
  • 再帰
  • ユーザー定義関数の呼び出し

Differences from Perl[編集]

PCREはPerl 5.9.4と比べて以下の違いがある。

再帰はPCREではアトミックに、Perlでは非アトミックに行う。
"<<!>!>!>><>>!>!>!>" =~ /^(<(?:[^<>]+|(?3)|(?1))*>)()(!>!>!>)$/という表現はPerlではマッチするがPCREではマッチしない。
The value of a capture buffer deriving from the ? quantifier (match 1 or 0 times) when nested in another quantified capture buffer is different
"aba" =~ /^(a(b)?)+$/; will result in $1 containing 'a' and $2 containing undef in Perl, but in PCRE will result in $2 containing 'b'.
?限量子から得られるキャプチャバッファの値は他のキャプチャバッファに入っているとき値が変わる。
"aba" =~ /^(a(b)?)+$/;という結果は$1で 'a' がキャプチャされることは同じだが、$2についてはPerlではundefだが、PCREでは'b'がキャプチャされる。
PCREは名前付きキャプチャを数値からはじめることができるが、Perlはベアワード(@,%,$などがつかない剥き出しの文字列)でなければならない。
\g{}はPerlでは曖昧性を持たないがPCREでは潜在的に多義であることを意味する。
PCRE does not support certain "experimental" Perl constructs
such as (??{...}) (a callback whose return is evaluated as being part of the pattern) nor the (?{}) construct, although the latter can be emulated using (?Cn). Recursion control verbs added in the Perl 5.9.x series are also not supported. Support for experimental backtracking control verbs (added in Perl 5.10) is available in PCRE since version 7.3. They are (*FAIL), (*F), (*PRUNE), (*SKIP), (*THEN), (*COMMIT), and (*ACCEPT). Perl's corresponding use of arguments with backtracking control verbs is not generally supported. Note however that since version 8.10, PCRE supports the following verbs with a specified argument: (*MARK:markName), (*SKIP:markName), (*PRUNE:markName), and (*THEN:markName).
PCREは明らかに実験的な表現をサポートしない
例えば(??{...})(?{})[8]が挙げられる。再帰はPerl 5.9.xでサポートされない。Support for experimental backtracking control verbs (added in Perl 5.10) is available in PCRE since version 7.3. They are (*FAIL), (*F), (*PRUNE), (*SKIP), (*THEN), (*COMMIT), and (*ACCEPT). Perl's corresponding use of arguments with backtracking control verbs is not generally supported. Note however that since version 8.10, PCRE supports the following verbs with a specified argument: (*MARK:markName), (*SKIP:markName), (*PRUNE:markName), and (*THEN:markName).
PCRE and Perl are slightly different in their tolerance of erroneous constructs
Perl allows quantifiers on the (?!) construct, which is meaningless but harmless (albeit inefficient); PCRE produces an error. (Note that such assertions can be harmlessly quantified with PCRE beginning with version 8.13, so the cited example applies only to earlier versions.)
PCRE has a hard limit on recursion depth, Perl does not
With default build options "bbbbXcXaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" =~ /.X(.+)+X/ will fail to match due to stack overflow, but Perl will match this correctly. Perl uses the heap for recursion and has no hard limit for recursion depth, whereas PCRE has a compile time hard limit.

With the exception of the above points PCRE is capable of passing the tests in the Perl 't/op/re_tests' file, one of the main syntax level regression tests for Perl's regular expression engine.

脚注[編集]

  1. ^ licence.txt”. 2009年5月31日閲覧。
  2. ^ a b PCRE - Perl Compatible Regular Expressions”. 2009年5月31日閲覧。
  3. ^ Overview of new features in Apache 2.2”. 2009年5月31日閲覧。
  4. ^ a b Postfix PCRE Support”. 2009年5月31日閲覧。 引用エラー: 無効な <ref> タグ; name "postfix"が異なる内容で複数回定義されています
  5. ^ Safari 3 Beta Update 3.0.3 のセキュリティコンテンツについて”. 2009年5月31日閲覧。
  6. ^ maildropfilter”. 2009年5月31日閲覧。
  7. ^ PCRE - Perl-compatible regular expressions”. University of Cambridge (2009年). Template:Cite webの呼び出しエラー:引数 accessdate は必須です。
  8. ^ (?Cn)でエミュレート可能

関連項目[編集]

外部リンク[編集]