regex - linux查找正则表达式

标签 regex linux bash unix find

我在使用 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/

相关文章:

regex - 优化 PowerShell 中的 RegEx 匹配

mysql - mysqladmin 和 password() 函数之间的哈希值不同

linux - sendmsg 系统调用是否验证添加到辅助数据中的 IPv6 源地址?

bash - 如何在 Bash 脚本中以 kb、mb、gb、b 为单位计算实际值

javascript - 正则表达式:在 url 登录/测试中获取字符串

java - 替换前两次出现的 '&' 字符之间的字符串

linux - logrotate:仅将新的压缩文件移动到 S3

bash - 从一系列 PDF 中删除第一页

bash - 如何找到当前的 shell 命令

javascript - 正则表达式不适用于波斯字符