There are some special characters to indicate a position in a line. These are the characters for the first position in a line and $ for the end of a line. So
//^a/looks for lines that begin with the character a.
//a$/looks for lines that end with the character a. This use of the character $ cannot interfere with the use of the dollar sign to indicate variables, so that the command line processor may substitute them (p. ).
The end-of-line character is indicated either by the two characters
\n
or by a linefeed character inside the pattern. The presence of
linefeeds inside the patterns isn't allowed in most regular expression
programs, but it can be very handy:
//\n{2,}/=/\n/This would remove all empty lines from a file. A word of caution is in order here. Substitutions of the type
//\n/=//would remove all linefeeds from a file. This would have the effect of making one giant line. Lines are however limited to 255 characters, so the replacements that would make longer lines are skipped.
When a character is needed that has a special meaning it should be
`escaped'. This can be done either by putting a backslash character in
front of it as in \$
to look for a dollar sign, or to put the
character <escape> in front of it. The use of either of these escape
characters switches the interpretation of the character off (with the
exception of the n with is used for the linefeed).