Examples of basic regular expressions

The following table contains examples of basic regular expressions. A dot (.) represents the space character.

Use this expression If you want to match
^$ An empty line
..* One or more spaces
[^][-] Any character except [, ], or -
[A-Z] or [[:upper:]] Any uppercase letter
[1-9][0-9]\{2\}-[0-9]\{4\} A local telephone number in the United States or Canada
[A-Z]\{3,} Three or more uppercase letters
\(and.*\)\{2,3\} Two or three occurrences of the word and, possibly separated by spaces
s/\([^.][^.]*\).\([^.][^.]*\)/\2 \1 Swap two words in ed(1), ex(1), or vi(1)
[_A-z][_A-z0-9]* A valid C-language variable name