我需要为备份排除过滤器编写正则表达式以排除文件夹及其所有子文件夹。
我需要匹配以下内容
folder1/statistics
folder1/statistics/*
folder2/statistics
folder2/statistics/*
我想出了这个正则表达式,它匹配文件夹统计信息,但不匹配统计文件夹的子文件夹。
[^/]+/statistics/
如何扩展此表达式以匹配统计文件夹下的所有子文件夹?
使用以下正则表达式:
/^[^\/]+\/statistics\/?(?:[^\/]+\/?)*$/gm
regex101 演示.
解释:
/
^ # matches start of line
[^\/]+ # matches any character other than / one or more times
\/statistics # matches /statistics
\/? # optionally matches /
(?: # non-capturing group
[^\/]+ # matches any character other than / one or more times
\/? # optionally matches /
)* # zero or more times
$ # matches end of line
/
g # global flag - matches all
m # multi-line flag - ^ and $ matches start and end of lines
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)