A Regular Expression Primer

This table breifly compares the regular exprssion capability of Perl, grep, egrep, and lex. This table does not include minimal matching, casefolding, and pattern substitution features of the various regular expression languages in each tool.

charsactionPerlgrepegreplex
abc...Match that character (metacharacters excluded)Perlgrepegreplex
\\\.\*...Match that metacharacter following the back slashPerluses shuses shlex
""De-meta any chars inside quotes   lex
\t,\n,\r,\ftab, newline, return, form feedPerlgrepegreplex
.Match any characterPerlgrepegreplex (not \n)
[]Character classPerlgrepegreplex
[^]Inverse Character classPerlgrepegreplex
[-]Character rangesPerlgrepegreplex
\wMatch a "word" character (alphanumeric plus "_")Perl   
\WMatch a non-word characterPerl   
\sMatch a whitespace characterPerl   
\SMatch a non-whitespace characterPerl   
\dMatch a digit characterPerl   
\DMatch a non-digit characterPerl   
anchorsactionPerlgrepegreplex
^Match the beginning of the linePerlgrepegreplex
$Match the end of the linePerlgrepegreplex
\bMatch a word boundaryPerl   
\BMatch a non-(word boundary)Perl   
operatorsactionPerlgrepegreplex
|AlternationPerl egreplex
()GroupingPerl egreplex
multiplicityactionPerlgrepegreplex
*Greedy match 0 or more timesPerlgrepegreplex
+Greedy match 1 or more timesPerl egreplex
?Greedy match 1 or 0 timesPerlgrepegreplex
{n}Greedy match exactly n timesPerl egrep 
{n,}Greedy match at least n timesPerl egrep 
{n,m}Greedy match at least n but not more than m timesPerl egreplex
lookAheadactionPerlgrepegreplex
/Look ahead predicate   lex
(?= )Look ahead predicatePerl   
(?! )NOT Look ahead predicatePerl   
Greedy means that it trys to find the longest pattern that matches from the point where the previous pattern left off.