views:

978

answers:

6

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)

+9  A: 

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.

chaos
I think GNU `grep` just support GNU BRE and GNU ERE. Because according to http://www.regular-expressions.info/refflavors.html POSIX BRE and POSIX ERE don’t support `\w` but GNU `grep` does.
Gumbo
The "special" grep he's referring to might be ack, which deserves mention.
Chris Lutz
+7  A: 

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. ;)

ojrac
+1  A: 

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

mipadi
There is not enough RTFM on this site!! ;)man regex
RandomNickName42
A: 

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.

Sander Marechal
+1  A: 

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.

Matthew Flower
+4  A: 

POSIX BRE (Basic Regular Expressions)

You can compare the various flavors here.

Trampas Kirk
Excellent link!
semiuseless
@semiuseless: So upvote it? :)
Trampas Kirk
Vote grubbing? Is that what we've come to?
Telemachus