我尝试使用 find
util 查找文件,并且我想查找除特殊目录中的文件之外的所有 *.js
文件。我尝试使用命令查找:
find ./ -regex '\.((?\!node_modules).)*\.js'
但是这个场景什么也没发现。
这个正则表达式适用于 Sublime Text 3,我已经在其中进行了测试。
附注我知道如何使用下面的其他选项来解决。但我想知道如何用正则表达式解决问题
find ./ -path *node_modules -prune -o -name *.js
最佳答案
您目前无法执行此操作。
GNU Find 支持多种正则表达式类型,但都不支持零宽度断言。
-regextype type Changes the regular expression syntax understood by -regex and -iregex tests which occur later on the command line. Currently-implemented types are emacs (this is the default), > posix-awk, posix-basic, posix- egrep and posix-extended.
对于您的任务,您需要后向断言, 目前还不支持。
您的另一个选择是使用 find2perl将 find 表达式转换为 perl 程序, 这与表达式的结果相同。
您可以使用此程序来检查您的表达式是否适用于 PCRE 和向前/向后断言。
关于正则表达式排除查找工具的单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38852260/