3
什麼模式在PHP中的意思是:解釋一下這個PHP正則表達式的手段(preg_match_all)
'#^/abc/(?P<abc>[^/]++)$#si'; // please expand this pattern's meaning.
什麼都字符串可以匹配此模式與preg_match_all
的?
什麼模式在PHP中的意思是:解釋一下這個PHP正則表達式的手段(preg_match_all)
'#^/abc/(?P<abc>[^/]++)$#si'; // please expand this pattern's meaning.
什麼都字符串可以匹配此模式與preg_match_all
的?
這種模式'#^/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_all
here
http://regex101.com – brandonscript
@remus這就是我夢想了多年的東西真棒, 非常感謝你 – baldrs