Question

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)

Was it helpful?

Solution

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 aka 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.

OTHER TIPS

POSIX BRE (Basic Regular Expressions)

You can compare the various flavors here.

There's a good write-up here. To quote the page, "grep is supposed to use BREs, except that grep -E uses EREs. (GNU grep fits some extensions in where POSIX leaves the behaviour unspecified)."

In other words, it's a long story. ;)

The grep man pages do a pretty thorough job of explaining the flavor of regexp available in grep. man grep is pretty useful.

Grep is an implementation of POSIX regular expressions. There are two types of posix regular expressions -- basic regular expressions and extended regular expressions. In grep, generally you use the -E option to allow extended regular expressions.

There is no regular grep function in PHP. If you are referring to the ereg family of PHP functions then those are POSIX regular expressions. If you are referring to the Linux grep commandline utility, those are POSIX regular expressions as well. It supports both basic as well as extended POSIX regular expressions.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top