根据man grep的解释:
Matcher Selection
-E, --extended-regexp
Interpret PATTERN as an extended regular expression (ERE, see below). (-E is specified by POSIX.)
-P, --perl-regexp
Interpret PATTERN as a Perl regular expression (PCRE, see below). This is highly experimental and grep -P may warn of unimplemented features.
在实际的情况中,如果我想找一个tomcat的进程,使用grep -E , 如下所示:
root@redhat:/etc/apache-tomcat# ps -eaf | grep tomcat | grep catalina.home | grep -v grep | grep -E "^(\w+|\d+)\s+\d+" -o
没有匹配到任何结果
而使用grep -P,如下所示:
root@redhat:/etc/apache-tomcat # ps -eaf | grep tomcat | grep catalina.home | grep -v grep | grep -P "^(\w+|\d+)\s+\d+" -o
root 6003
可以显示出如上的结果
我想问一下grep -P支持的哪些正则表达式,而grep -E是不支持的?
grep -P具体比grep -E强在哪些地方?
|