정규식(PCRE) PCRE Patterns Comments

시퀀스(?#는 다음 닫는 괄호까지 계속되는 주석의 시작을 표시합니다. 중첩된 괄호는 허용되지 않습니다. 주석을 구성하는 문자는 패턴 일치에서 전혀 역할을 하지 않습니다.

PCRE_EXTENDED 옵션이 설정된 경우 문자 클래스 외부의 이스케이프 처리되지 않은 # 문자는 패턴의 다음 줄 바꿈 문자까지 계속되는 주석을 도입합니다.

예제 #1 PCRE 패턴에서 주석 사용

                  
<?php
$subject = 'test';

/* (?# can be used to add comments without enabling PCRE_EXTENDED */
$match = preg_match('/te(?# this is a comment)st/', $subject);
var_dump($match);

/* Whitespace and # is treated as part of the pattern unless PCRE_EXTENDED is enabled */
$match = preg_match('/te   #~~~~
st/', $subject);
var_dump($match);

/* When PCRE_EXTENDED is enabled, all whitespace data characters and anything
   that follows an unescaped # on the same line is ignored */
$match = preg_match('/te    #~~~~
st/x', $subject);
var_dump($match);
                  
                

위의 예는 다음을 출력합니다.

int(1)
int(0)
int(1)