问题描述
以下命令无法从 16714正确捕获
16714
ssh -f -N -T -R3300:localhost:22
pre $ lt; code> egrep -o'^ [^] +(?=。* [R] 3300:localhost:22) '
(但是,如果使用-P标志,交换到grep会执行此操作,我期待egrep是能够处理这个)
grep -P
Perl regexp引擎。
egrep
与 grep -E
相同,它会强制grep使用ERE(扩展正则表达式)引擎,它不支持lookahead。
您可以在这里找到Perl和ERE(以及其他)之间差异的快速参考: p>
The following command does not correctly capture the 16714
from 16714 ssh -f -N -T -R3300:localhost:22
egrep -o '^[^ ]+(?= .*[R]3300:localhost:22)'
(However swapping to grep does if you use the -P flag. I was expecting egrep to be able to handle this)
grep -P
forces grep to use the Perl regexp engine.egrep
is the same as grep -E
and it forces grep to use the ERE (extended regular expression) engine, that does not support lookahead.
You can find a quick reference of the differences between Perl and ERE (and others) here : http://www.greenend.org.uk/rjk/tech/regexp.html
这篇关于如何编写egrep中的非捕获组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!