Regular expression syntax provides several metacharacters for matching the occurrence of patterns.
The following table shows the most common types:
Note the similarity between these metacharacters and the shells file name wildcards.
The shell uses a question mark (?) to match a single character, whereas regular expressions use a dot (.).
In file name matching, the shell uses * to match one or more of the preceding characters.
Using * with regular expressions matches zero or more characters. Brackets work the same way in either situation.
You can combine metacharacters. For example, you can use .* to match zero or more instances of any character.
The following slide show shows some grep commands that search the file /usr/dict/words.
This system file is a standard part of many versions of UNIX. It contains a list of words, one per line.
Click the Quiz link below to answer some questions about regular expressions, quoting, and the
Matching Patterns - Quiz