grep:重复运算符操作数无效

grep:重复运算符操作数无效,grep,ack,Grep,Ack,我有一个常规的express(?grep不支持(?)? 由于最近的原因,要在macOS上使用GNU grep,您必须在命令前面加上“g” $ ggrep -Pio '(?<=heads\/)(.*?)(?=\n)' text.txt # P option instead of E $ggrep-Pio'(?试试这个 grep -Eoh 'heads/.*' text.txt | grep -Eoh '/.*' | grep -Eoh '[a-zA-Z].*' 在您的系统上,grep和a

我有一个常规的express
(?grep不支持
(?)?
由于最近的原因,要在macOS上使用GNU grep,您必须在命令前面加上“g”

$ ggrep -Pio '(?<=heads\/)(.*?)(?=\n)' text.txt # P option instead of E
$ggrep-Pio'(?试试这个

grep -Eoh 'heads/.*' text.txt | grep -Eoh '/.*' | grep -Eoh '[a-zA-Z].*'

在您的系统上,grep和ack接受的正则表达式语法似乎略有不同。请从正则表达式中删除重复字符,直到找到grep不喜欢的字符。我的错误。我将其编辑为正确。同样的问题。您误解了我的评论。我是说grep正则表达式语言和ack正则表达式语言不是相同的同样。我正试图帮助你自己调试这个问题以找出差异。(.)jspooner:我是ack的作者,问题是ack使用Perl正则表达式,因为它是一个Perl应用程序。grep不使用Perl正则表达式,因此正如你所发现的,存在差异。至于“我在这台机器上没有ack”,ack是一个文件,您可以在处使用单个命令行下载,无需root priv。我使用了*,感谢您提供的解决方案,与我配合良好。如果grep现在不支持-P,该怎么办?@Irina您的意思是什么?它应该仍然支持
-P
74f3649af36984e1b784e46502fe318e91d29570    HEAD
06d4463ab47a6246e6bd94dc3b9267d59fc16c2e    refs/heads/ARC
0597e13c22b6397a1b260951f9d064f668b26f08    refs/heads/LocationAge
e7e1ed942d15efb387c878b9d0335b37560c8807    refs/heads/feature/311-312-breaking-banner-updates
d0b2632b465702d840a358d0b192198ae505011c    refs/heads/gulf-news
509173eafc6792739787787de0d23b0c804d4593    refs/heads/jbb-new-applicationdidfinishlaunching
1e7b03ce75b1a7ba47ff4fb5128bc0bf43a7393b    refs/heads/locationdebug
74f3649af36984e1b784e46502fe318e91d29570    refs/heads/master
5d2ede384325877c24db7ba1ba0338dc7b7f84fb    refs/heads/mixed-media
3f3b6a81dd3baea8744aec6b95c2fe4aaeb20ea3    refs/heads/post-onezero
4198a43aab2dfe72d7ae9e9e53fbb401fc9dac1f    refs/heads/whitelabel
76741013b3b2200de29f53800d51dfd6dc7bac5e    refs/tags/r10
fc53b1a05dad3072614fb397a228819a67615b82    refs/tags/r10^{}
afdcfd970c9387f6fda0390ef781c2776aa666c3    refs/tags/r11
$ grep -Pio '(?<=heads\/)(.*?)(?=\n)' text.txt # P option instead of E
$ brew install grep 
$ ggrep -Pio '(?<=heads\/)(.*?)(?=\n)' text.txt # P option instead of E
grep -Eoh 'heads/.*' text.txt | grep -Eoh '/.*' | grep -Eoh '[a-zA-Z].*'