Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What flavour of regular expression is grep?

Tags:

grep

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)

like image 479
nevan king Avatar asked Jul 02 '09 15:07

nevan king


People also ask

Is grep a regular expression?

grep is one of the most useful and powerful commands in Linux for text processing. grep searches one or more input files for lines that match a regular expression and writes each matching line to standard output.

What is regular expression explain grep command?

You can also use the grep command to search for targets that are defined as patterns by using regular expressions. Regular expressions consist of letters and numbers, in addition to characters with special meaning to grep . These special characters, called metacharacters, also have special meaning to the system.

What are the flavors of regular expressions?

Different Flavors of Regular Expressions Regular expressions (RE), as defined by POSIX, come in two flavors: extended regular expressions (ERE) and basic regular expressions (BRE). EREs are roughly those of the traditional egrep, while BREs are roughly those of the traditional ed.

What are grep patterns called?

A grep pattern, also known as a regular expression, describes the text that you are looking for. For instance, a pattern can describe words that begin with C and end in l.


1 Answers

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.

like image 114
chaos Avatar answered Oct 10 '22 16:10

chaos