正则表达式-显示目录,不包括首页

时间:2018-10-30 11:46:42

标签: regex

如何显示某些目录并排除首页“ /”

当前代码包括首页

^\/(app|page|create|examples|es)?($|\/).*

我要显示的页面

/app
/app/1231
/page
/page/abc
/create/1231
/es
/examples
/examples/abc/test

我不想显示的页面

/  (frontpage)
/page-1231
/createabc
esda

1 个答案:

答案 0 :(得分:1)

我建议使用

^\/(app|page|create|examples|es)(?:\/.*)?$

请参见regex demo

详细信息

  • ^-字符串的开头
  • \/-斜杠
  • (app|page|create|examples|es)-替代子字符串之一
  • (?:\/.*)?-可选的子字符串:/以及除换行符以外的其他0个或多个字符,应尽可能多
  • $-字符串的结尾。
相关问题