开发者

a question about preg_match

I have a question in PHP:

When using preg_match开发者_开发知识库, why #^(([a-z]{2})/)?(([a-z\-]{3,})/(([a-z\-]{3,}))?)?$#i match ab/cde/fgh and do not match ab/cde?

(I mean:

preg_match_all('#^(([a-z]{2})/)?(([a-z\-]{3,})/(([a-z\-]{3,}))?)?$#i','ab/cde/fgh',$match)

$match =  Array
(
    [0] => ab/cde/fgd
    [1] => ab/
    [2] => ab
    [3] => cde/fgd
    [4] => cde
    [5] => fgd
    [6] => fgd
)

and

preg_match_all('#^(([a-z]{2})/)?(([a-z\-]{3,})/(([a-z\-]{3,}))?)?$#i','ab/cde',$match)
$match = Array ()


Because as the regex is written, you need a slash after the cde. ab/cde/ should match.


[a-z-]{3,} = 3 or more characters

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜