如何匹配导航子项(仅限index.php)也包括在子级之后的第一级(参见最后两个示例)。
administration / peoples / index.php(匹配)
administration / peoples / roles.php(不匹配)
administration / analytics / index.php(匹配)
administration / publications / index.php(匹配)
administration / publications / set.php(不匹配)
administration / publications / test / index.php(匹配!重要)
administration / publications / test / subtest / index.php(不匹配!重要)
THX
答案 0 :(得分:1)
单向(perl风味)。据我所知,第一个文件夹必须是'administration',最后一个文件必须是'index.php',并且必须是它们之间的一个或两个子文件夹。
m|^(?i:administration)/(?:[^/]+/){1,2}(?i:index\.php)\s*$|
说明:
m|...| # Regex expresion, pipe is separator to avoid escape slashes inside regex.
^ # (zero-width) Begin of line.
(?i:administration)/ # Literal string 'administration/' ignoring case.
(?:[^/]+/){1,2} # Any characters plus a slash one or two times.
(?i:index\.php) # Literal string 'index.php' ignoring case.
\s* # Posible space characters after string, maybe zero.
$ # (zero-width) End of line.
答案 1 :(得分:0)
改为使用字符串操作:
administration/
开头,则不匹配,跳过; /index.php
结尾,则不匹配,跳过; /test/
,则不重要。这里不需要正则表达式!
答案 2 :(得分:-1)
#^administration/(.*?)index.php$#