The utilities ed(1), ex(1), expr(1), more(1), sed(1), and vi(1) use basic regular expressions. These utilities use the following metacharacters:
* . ^ $ [ ] \ \( \) \{ \}
The following table summarizes how these metacharacters are used.
Sample pattern | Description |
---|---|
. | Matches any single character. |
^ | Matches the beginning of a line, but only if it occurs at the beginning of the regular expression. |
$ | Matches the end of a line, but only if it occurs at the end of the regular expression. |
[c] | A character set. Matches any one of the characters between the brackets. For example, [abc] matches a or b or c. |
[^c] | Matches any one character that is not between the brackets. For example, [^abc] matches any character except a or b or c. |
dog* | Matches zero or more occurrences of the pattern that precedes the asterisk (*). For example, a matches a, but a* matches a, aa, aaa, and so on. The pattern a* also matches a zero string. |
\c | Matches the literal character c, except where noted below. The digits 1 through 9 have a special meaning. See the description of \n. |
\(dog\) | Match the characters between the parentheses as a group. For example, ban* matches ba, ban, bann, and so on, but b\(an\)* matches b, ban, banan, and so on. Also used for substitution. See \n. |
dog\{n\} | Matches n occurrences of the pattern dog. |
dog\{n,\} | Match n or more occurrences of the pattern dog. |
dog\{n,p\} | Matches between n and p occurrences of the pattern dog. The number n must be less than the number p. |
\n | Matches the instance of the grouping in the pattern specified by n, grouped with \( \). For example, given the pattern \(a\)\(b\)\(c\), \1 stands for a, \2 for b, and \3 for c. The number n must be a digit from 1 to 9. |