我在使用 find
命令的正则表达式时遇到问题。可能是我不明白在命令行上转义的东西。
为什么这些不一样?
find -regex '.*[1234567890]'
find -regex '.*[[:digit:]]'
Bash、Ubuntu
最佳答案
你应该看看 find
的 -regextype
参数,见 manpage :
-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.
我猜 emacs
类型不支持 [[:digit:]]
构造。我尝试使用 posix-extended
并按预期工作:
find -regextype posix-extended -regex '.*[1234567890]'
find -regextype posix-extended -regex '.*[[:digit:]]'
关于regex - linux查找正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5635651/