regex - 正则表达式问题

标签 regex linux grep

可能这是新手问题,但我必须问!
一般来说,我理解正则表达式,但我不明白,为什么这个:

^.{8}[[:blank:]]{2}

在这条线上工作:

prelink: /lib/libkeyutils-1.2.so: at least one of file's dependencies has changed since prelinking

在这个 grep 命令中:

echo "prelink: /lib/libkeyutils-1.2.so: at least one of file's dependencies has changed since prelinking" | grep -v '^.\{8\}[[:blank:]]\{2\}'

哪里:

The                says "beggining of line"  
The .{8}           says "any eight characters"  
The [[:blank:]]{2} says "any two space characters"  

So ^.{8} match "prelink:", when [[:blank:]]{2} need matching "  " (two spaces), but we have only " " (one space)... So why this work at all, and if this work why this one:

^.{8}[[:blank:]]{1} 

不起作用?

谢谢你提前。

最佳答案

您正在使用 grep-v 选项,这导致它打印匹配的行。删除 -v,它将按您预期的那样工作。

grep --help
...
   -v, --invert-match        select non-matching lines
...

关于regex - 正则表达式问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3461584/

相关文章:

c++ - 微软对 std::regex 的实现

regex - 否定多个词

javascript - 我无法在主机上启动 node.js

Linux:我如何从一个字符串到另一个字符串进行grep文本

java - 使用单个正则表达式验证每一行

regex - perl 正则表达式来分隔文本中的每个字母

linux - 使用 EOF 在未命名管道上发送信号

c - 通过 fopen 创建文件在 Linux 上运行良好但在 Windows 上运行不正常(MS VS 2010)

linux - Bash:为什么对这个字符串进行 egrepping 会成功?

regex - 如何让 "grep -zoP"分别显示每个匹配项?