Grep 不匹配正则表达式 [英] Grep not matching regular expression
本文介绍了Grep 不匹配正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在努力从 grep
获得匹配结果.
I'm strugging a bit to get matching results from grep
.
给定以下输入文件的内容
Given the following input file's contents
{"foo":29, "bar":30}
{"foo":29, "bar":30}
和以下命令 grep -o '"[^"]+":[0-9]+' input.txt
,我期待两个匹配的结果.据我所知它支持正则表达式,但我不明白为什么 grep
不返回任何结果?
and the following command grep -o '"[^"]+":[0-9]+' input.txt
, I'm expecting two matching results. As far as I know it supports regular expressions, but I don't understand why grep
doesn't return any results?
正则表达式的其他实现工作正常(https://regex101.com/r/RcONXk/1).
Other implementations of regexp are working fine (https://regex101.com/r/RcONXk/1).
推荐答案
你可以试试这个;
grep -oE '"[^"]+":[0-9]+'
例如:
user@host:/tmp$ echo '{"foo":29, "bar":30}' | grep -oE '"[^"]+":[0-9]+'
"foo":29
"bar":30
男人 grep :
-E, --extended-regexp
Interpret PATTERN as an extended regular expression (ERE, see below). (-E is specified by POSIX.)
这篇关于Grep 不匹配正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文