gpt4 book ai didi

带有 fswatch 的正则表达式 - 排除不以 ".txt"结尾的文件

转载 作者:行者123 更新时间:2023-11-29 09:38:10 25 4
gpt4 key购买 nike

对于文件列表,我想匹配那些不以 .txt 结尾的文件。我目前正在使用这个表达式:

.*(txt$)|(html\.txt$)

This expression will match everything ending in .txt, but I'd like it to do the opposite.


应该匹配:

happiness.html
joy.png
fear.src

应该 匹配:

madness.html.txt
excitement.txt

我想得到这个,这样我就可以将它与 fswatch 搭配使用:

fswatch -0 -e 'regex here' . | xargs -0 -n 1 -I {} echo "{} has been changed"

问题是它似乎不起作用。

PS:我使用标签 bash 而不是 fswatch,因为我没有足够的信誉点来创建它。对不起!

最佳答案

尝试使用 lookbehind,像这样:

.*$(?<!\.txt)

Demonstration

基本上,这匹配任何文本行,只要最后 4 个字符不是 ".txt"

关于带有 fswatch 的正则表达式 - 排除不以 ".txt"结尾的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26616949/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com