英文:
regex to exclude non golang files not working with inotifywait
问题
以下是用于过滤所有非go文件(即扩展名为'.go'的文件)的正则表达式:
^([\S][^.][^g][^o]|[\S].[^g].|[\S]..[^o]$|[\S][^.]..|[\S]{1,2})$
^([^.]*)($|.)
你可以在这里测试它们(在正则表达式下方的菜单中点击“尝试”Go):
尽管它们在Go中似乎工作正常,但在inotifywait
的排除过滤器中(使用posix ERE格式)却不起作用。
我正在尝试为我的Go项目在Makefile中设置一个“监视和重新加载”任务。同时,我假设文件或文件夹名称中不包含空格。
英文:
Below are the regex for filtering out all the non go files (i.e those with '.go' extension)
^([\S]*[^.][^g][^o]|[\S]*.[^g].|[\S]*..[^o]$|[\S]*[^.]..|[\S]{1,2})$
^([^.]*)($|[.]($|[\S]$|g[^o]$|[^g]o$|[^g][^o]$|([\S]+)\.($|.$|g[^o]$|[^g]o$|[^g][^o]$|[^.]{3,}$)|[^.]{3,}$))
You can test them here (click on try it 'Go' in the menu below the regex)
While they seem to work correctly in go but not with inotifywait
's exclude filter (which uses posix ERE format)
I am trying to setup a "watch and reload" task in my Makefile for a golang project. Also i am assuming file or folders names dont have spaces.
答案1
得分: 1
收到了。看起来[:graph:]
不是扩展posix中非空格字符的类标识符。以下是可以使用的正则表达式:
^[[:graph:]]*[^.][^g][^o]$|^[[:graph:]]{1,2}$|^[[:graph:]]*.[^g].$|^[[:graph:]]*..[^o]$|^[[:graph:]]*[^.]..$
或者根据stribizhev的评论,以下是更好的正则表达式:
[^.][^g][^o]$|^..$|.[^g].$|..[^o]$|[^.]..$
英文:
Got the issue. It seems [:graph:]
not \S
the class identifier for non-space chars in extended posix. The below is good to go.
^[[:graph:]]*[^.][^g][^o]$|^[[:graph:]]{1,2}$|^[[:graph:]]*.[^g].$|^[[:graph:]]*..[^o]$|^[[:graph:]]*[^.]..$
or even a better one from stribizhev comment [^.][^g][^o]$|^..$|.[^g].$|..[^o]$|[^.]..$
答案2
得分: 1
你可以使用以下正则表达式进行匹配:
.[^.][^.][^.]+$|.[^.][^o]$|.[^g][^.]$|.[^.]$
请参考演示
或者如果你可以进行分组:
.([^.][^.][^.]+|[^.][^o]|[^g][^.]|[^.])$
请参考演示
解释如下:
-
\.
- 匹配一个点号 -
([^.][^.][^.]+|[^.][^o]|[^g][^.]|[^.])
- 一个包含多个选择的分组:[^.][^.][^.]+
- 匹配两个非点号字符和一个或多个非点号字符...[^.][^o]
- 匹配一个非点号字符和一个非o字符...[^g][^.]
- 匹配一个非g字符和一个非点号字符...[^.]
- 匹配一个非点号字符...
-
$
- 匹配字符串的末尾。
英文:
You may use
\.[^.][^.][^.]+$|\.[^.][^o]$|\.[^g][^.]$|\.[^.]$
See demo
Or if you can group:
\.([^.][^.][^.]+|[^.][^o]|[^g][^.]|[^.])$
See demo
See explanation:
\.
- a literal dot([^.][^.][^.]+|[^.][^o]|[^g][^.]|[^.])
- a group of alternatives:[^.][^.][^.]+
- 2 characters other than.
and 1 or more characters other than.
...[^.][^o]
- a character other than a dot and a character other thano
...[^g][^.]
- a character other thang
and a character other than a dot...[^.]
- a character other than a dot...
$
- right before the end of string.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论