What flavour of regular expression is grep?

nevan king picture nevan king · Jul 2, 2009 · Viewed 8.5k times · Source

I'm guessing it's not a Perl Compatible Regular Expression, since there's a special kind of grep which is specifically PCRE. What's grep most similar to?

Are there any special quirks of grep that I need to know about? (I'm used to Perl and the preg functions in PHP)

Answer

chaos picture chaos · Jul 2, 2009

Default GNU grep behavior is to use a slightly flavorful variant on POSIX basic regular expressions, with a similarly tweaked species of POSIX extended regular expressions for egrep (usually an alias for grep -E). POSIX ERE is what PHP ereg() uses.

GNU grep also claims to support grep -P for PCRE, by the way. So no terribly special kind of grep required.