The sed regular expressions are essentially the same as the grep regular expressions. They are summarized below.
^ |
matches the beginning of the line |
$ |
matches the end of the line |
. |
Matches any single character |
(character)* |
match arbitrarily many occurences of (character) |
(character)? |
Match 0 or 1 instance of (character) |
[abcdef] |
Match any character enclosed in [] (in this instance, a b c d e or f) ranges of characters such as [a-z] are permitted. The behaviourof this deserves more description. See the page on grep for more details about the syntax of lists. |
[^abcdef] |
Match any character NOT enclosed in [] (in this instance, any character other than a b c d e or f) |
(character)\{m,n\} |
Match m-n repetitions of (character) |
(character)\{m,\} |
Match m or more repetitions of (character) |
(character)\{,n\} |
Match n or less (possibly 0) repetitions of (character) |
(character)\{n\} |
Match exactly n repetitions of (character) |
\(expression\) |
Group operator. |
\n |
Backreference – matches nth group |
expression1\|expression2 |
Matches expression1 or expression 2. Works with GNU sed, but this feature might not work with other forms of sed. |
