在PHP中模式是什么意思:
'#^/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>[^/]++)$
使用单行和不区分大小写的修饰符。)
还要注意两个++
符号的使用,这会将行为从贪婪变为占有欲。
匹配的字符串示例:
/abc/somethingelsenotafrontslash
您可以阅读有关以下内容的简要说明: preg_match_all
here
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句