本文介绍了如何编写egrep中的非捕获组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

以下命令无法从 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中的非捕获组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-09 01:09