ag: Search all folders except for folderName/subFolder (Perl Regex)

送分小仙女□ 提交于 2019-12-04 06:11:56

问题


I have these folders that have subfolders in them...

locales/US/en
locales/US/fr
locales/FR/en
locales/FR/fr
locales/DE/en
locales/DE/fr
public
test
[...]

I want Silver Searcher to ignore locales/* EXCEPT for locales/US/en/* (essentially I only care about US/en locale files)

This works, EXCEPT that it doesn't show the other folders in root (public and test):
ag -l -G '(locales)/(US)'

I believe AG uses Perl Regexes. Any thoughts?


回答1:


If it is perl regular expressions this should give you the expected result:

^(?:locales/US/en|(?!locales))

Explanation:

^   = anchor regular expression to start of string.
(?: = group which is not captured
|   = Alternation for alternative capture
(?! = negative look ahead assertion - ensures that the string isnt starting with locales, unless it is starting with locales/US/en


来源:https://stackoverflow.com/questions/35740753/ag-search-all-folders-except-for-foldername-subfolder-perl-regex

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!