linux 学习过程中的坑之 find 正则表达式

1 标准的正则表示式 格式
. 表示任意单个字符

  • 表示任意次数
    + 表示1次或1次以上
    {3} 表示精确匹配次数为3次
    {n,m}表示n次到m 次之间
    ^ 行首锚定 $行尾锚定
    \< 单词首部锚定 \> 单词尾部锚定
    2 扩展的正则表达式 相对标准的正则表达式 在次数表示的方面只是少了\ 其他都一样
    那么问题来了
    find -regex 此时的regex 是使用的正则表达式
    linux 学习过程中的坑之 find 正则表达式
    此时用到+ 没有使用+ 表示他是使用的扩展的正则表达式,
    在实验环境中 所有的文件为 issue issue1 s1 scripts/ ssss
    find -regex ".s{1,}" 的命令既然无法匹配 到ssss 此文件
    find -regex ".
    "s+ 命令却可以匹配

    迷惑中搜度娘 看看有没有帮助 发现一文章
    linux 学习过程中的坑之 find 正则表达式

    我们的问题是一致的,那么这个 -regex的选项 到底是不是我们平时使用的正则表达式了?
    man 帮助文档
    -regex pattern
    File name matches regular expression pattern. This is a match on the whole path, not a search. For example, to match a file named ./fubar3', you can<br/>use the regular expression.bar.' or `.b.3', but not `f.r3'. The regular expressions understood by find are by default Emacs Regular Expressions,
    but this can be changed with the -regextype option.

        发现没有说明 只是说有个 -regextype 选项有介绍他采用的模式
         -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 风格的 非我们常用的 posix-egrep and posix-extended 格式的正则表达式。问题解决 ,
总结 新手在学习过程中第一时间肯定是怀疑自己的命令输入有问题,根本就不会考虑使用不同风格的问题,等自己确定自己的命令输入没有问题了,才会开始查帮助文档。总的来说 官方的文档其实还是挺全的,就是英语不好的同学,查看起来特别花时间。

转载于:https://blog.51cto.com/2858259639/2394146

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值