The man pages for grep
on Ubuntu 18.04 and CentOS 8 have this to say about the -P
option for grep:
-P, --perl-regexp Interpret the pattern as a Perl-compatible regular expression (PCRE). This is experimental and grep -P may warn of unimplemented features.
I have put emphasis on "experimental" and "may warn". Experimental implies it's not suitable for production. "may warn" implies that you could run into an unimplemented feature and grep
could fail to warn you about it.
On older versions of grep
, I have even seen the phrase "highly experimental" instead of just "experimental".
Is the -P
option to GNU grep
safe to use in production? Some of my bootstrapping scripts need certain perl features, so this option is quite useful to me when perl has not already been installed/included.
grep -P
is of course absolutely non-portable; but if it works on your system, why not just use it?grep -P
is based on thepcre
library, which is already used all over the place. IMLE it'sgrep -E
which may get pathologically slow on some innocent regexes + inputs whichgrep -P
will breeze through (but, unfortunately I don't have any examples at hand).fold
hacks to work with grapheme clusters (I was actually shocked that it's implementation offold
even supported grapheme clusters). I just like to know I have options available out of the box before I have started installing packages.