2014-01-30 1 views
3

패턴은 PHP에서 무엇을 의미하는 설명 :이 PHP 정규 표현식 수단 (으로, preg_match_all가)

'#^/abc/(?P<abc>[^/]++)$#si'; // please expand this pattern's meaning.

및 문자열 preg_match_all이 패턴 무엇을 일치시킬 수 있습니다을?

+3

http://regex101.com – brandonscript

+0

그 @remus에 대한 간단한 설명을 읽을 수 있습니다 내가 년 동안 꿈꿔 멋진 일이야 , 대단히 감사합니다. – baldrs

답변

5

과 같이 분류이 패턴 '#^/abc/(?P<abc>[^/]++)$#si'; :

/^\/abc\/(?P<abc>[^\/]++)$/si 

^ assert position at start of the string 
\/ matches the character/literally 
abc matches the characters abc literally (case insensitive) 
\/ matches the character/literally 
(?P<abc>[^\/]++) Named capturing group abc 
    [^\/]++ match a single character not present in the list below 
     Quantifier: Between one and unlimited times, as many times as possible, without giving back [possessive] 
     \/ matches the character/literally 
$ assert position at end of the string 
s modifier: single line. Dot matches newline characters 
i modifier: insensitive. Case insensitive match (ignores case of [a-zA-Z]) 

(출처 : http://regex101.com/r/hS6qE3 - 그것은 /을 가정으로 당신이 사이트에 /을 탈출하기는 PHP를 구분 당신의 패턴에서. 예를 들어 #은 구분 기호로 대신 사용되며 따옴표로 묶여 있고 문자열 종료자인 ;입니다. 실제 표현식은 ^/abc/(?P<abc>[^/]++)$이며 단락 및 대소 문자를 구분하지 않습니다.

두 개의 ++ 표지판도 사용합니다 (changes the behavior from greedy to possessive).

일치하는 문자열의 예 :

/abc/somethingelsenotafrontslash 

당신은 preg_match_allhere