コメント

コメントは、(?# という並びにより始まり、次の閉じカッコで終わります。 カッコのネストはできません。コメント内の文字は、パターンマッチには 全く関係しません。

PCRE_EXTENDED オプションが設定されている場合は、パターン中の文字クラス外にある エスケープされていない # 文字からもコメントが始まり、 次の改行文字で終わります。

add a note add a note

User Contributed Notes 1 note

up
-2
asamaru at asamaru dot net
7 years ago
<?php
$string
= 'test';
echo
preg_match('/te(?# comments)st/', $string) . "\n";
echo
preg_match('/te#~~~~
st/'
, $string) . "\n";
echo
preg_match('/te#~~~~
st/x'
, $string) . "\n";

// result
// 1
// 0
// 1
To Top