前の記事 «:PHPとGDを使って色々作るサンプル
次の記事 »:ページ読み込み状況をグラフ化するPEAR::HTML_Progress2

PHP正規表現のクイックリファレンス

2006年07月26日

スポンサード リンク
PHP Regular Expressions - Spellbook - IT mage’s best friend
PHP offers you two complete regular expression handlers. Functions such as ereg and eregi use POSIX style matching, and functions such as preg_match use Perl 5 style matching. How to choose which to use? New users tend to go with ereg and friends, and the geeks who want as much power as they can muster in as few characters as possible go to preg_match.

PHP正規表現のクイックリファレンスが表としてまとまったものが公開されています。
知らない点があったら軽く覚えておきましょう。



以下、ちょっと知られていなさそうな点をまとめ

・cJやcGのようにcを付けることでコントロールコードになる
・xAAのようにして16進文字列を使う
・[[:space:]] で space,n,r,t にマッチ
・[[:alpha:]]ですべてのアルファベットにマッチ
・[[:digit:]]ですべての数字にマッチ

[[:〜:]]形式のものは他にも次のようなものがあります。

[[:cntrl:]] コントロールコード
[[:upper:]] 大文字半角英数 A-Z
[[:lower:]] 小文字半角英数 a-z
[[:alnum:]] 半角英数

関連サイト
PHP&正規表現 - phpspot

スポンサード リンク

投稿者 KJ : 2006年07月26日 15:05 | ブックマークに追加する Subscribe with livedoor Reader
間違いの指摘をしていただける方はメールでお願いします


本を執筆しました。