Contents / Previous / Next


Regular Expressions

       [ ]    matches any single character enclosed 

       [^ ]   matches any character not in the list

       [ - ]  matches any character in the range

       [:alpha:] matches any letter
       [:digit:] matches any digit

       .      matches any character

       \< and \> respectively match the empty string 
                 at the beginning and end of a word.

       \b     matches the empty string at the edge of a word

       \B     matches the empty string provided it is not 
              at the edge of a word

       \      to specify most special characters by adding
              a \ character before them, for example, use \[ 
              for an actual [

       ?      The preceding item is optional and matched at  most
              once.
       *      The  preceding  item  will  be matched zero or more
              times.
       +      The preceding item will  be  matched  one  or  more
              times.
       {n}    The preceding item is matched exactly n times.
       {n,}   The preceding item is matched n or more times.
       {n,m}  The preceding item is matched at least n times, but
              not more than m times.

       ^ (caret)  matches empty string at the beginning of a line.
       $ (dollar) matches empty string at the end  of a line.

       |       logical or of two regular expressions
      \( \) or ( )   can surround several strings, separated by |


 In basic regular expressions (option -e ) the metacharacters 
 ?, +, {, |, (, and )  lose their special meaning; instead 
 use the backslashed versions \?, \+, \{, \|, \(, and \).

Examples:

  Matches, for example, a line containing felix:

     grep -E '^[e-l]*x$' test.txt 

  Matches, for example, the word felix:

     grep -E '\<[e-l]*x\>' test.txt 

  Searching recursively for document about the Z-Buffer:

  grep -R -E '[zZ].?(b|B)uffer' *