The fundamental format for regular expressions is one of the following, depending on what you are trying to do:
/search_pattern/modifiers |
command/search_pattern/modifiers |
command/search_pattern/replacement/modifiers |
The first syntax is a basic search syntax. In the absence of a command prefix, such a regular expression returns the lines matching the search pattern. In some cases, the slash marks may be (or must be) omitted—in the pattern argument to the grep command, for example.
The second syntax is used for most commands. In this form, some operation occurs on lines matching the pattern. This may be a form of matching, or it may involve removing the portions of the line that match the pattern.
The third syntax is used for substitution commands. These can be thought of as a more complex form of search and replace.
For example, the following command will search for the word 'test' within the specified file:
# Expression: /test/ |
grep 'test' poem.txt |
Note: Note that grep expects the leading and trailing slashes in the regular expression to be removed.
The availability of commands and flags varies somewhat between regular expression variants, and is described in the relevant sections.
Last updated: 2008-04-08