我在使用正则表达式时遇到麻烦 find
命令。关于在命令行上转义,可能是我不了解的事情。
为什么这些不一样?
find -regex '.*[1234567890]'
find -regex '.*[[:digit:]]'
Bash,Ubuntu
Answers:
您应该看看的-regextype
参数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.
我猜该emacs
类型不支持该[[:digit:]]
构造。我尝试过posix-extended
,它按预期工作:
find -regextype posix-extended -regex '.*[1234567890]'
find -regextype posix-extended -regex '.*[[:digit:]]'