You may have noticed that things just don't work right when you used
some characters like ``.'', ``*'', ``$'', and others in
context searches and the substitute command.
The reason is rather complex, although the cure is simple.
treats these characters as special, with special meanings.
in a context search or the first string of the substitute command only,
\*. means ``any character,'' not a period, so
means ``a line with an x,
just ``a line with an x, a period, and a y.''~
A complete list of the special characters
that can cause trouble is the following:
The backslash character \\ is special to
If you have to use one of the special characters
you can turn off its magic meaning temporarily
by preceding it with the backslash.
s/\\\\\\\*.\\*/backslash dot star/
will change ``\\\*.*'' into ``backslash dot star''.
Here is a hurried synopsis of the other special characters.
First, the circumflex `` ^ ''
finds ``string'' only if it is at the beginning of a line:
The dollar-sign ``$'' is just the opposite of the circumflex;
it means the end of a line:
will only find an occurrence of ``string''
that is at the end of some line.
will find only a line that contains just ``string'',
finds a line containing exactly one character.
The character ``\*.'', as we mentioned above,
This is useful in conjunction with ``*'',
which is a repetition character;
``a*'' is a shorthand for ``any number of a's,''
so ``\*.*'' matches any number of anythings.
which changes an entire line,
which deletes all characters in the line up to and
including the last comma.
``\*.*'' finds the longest possible match,
this goes up to the last comma.)
``['' is used with ``]'' to form ``character classes'';
matches any single digit _
any one of the characters inside the braces
Finally, the ``&'' is another shorthand character -
it is used only on the right-hand part of a substitute command
where it means ``whatever was matched on the left-hand side''.
It is used to save typing.
Suppose the current line contained
and we wanted to put parentheses around it.
We could just retype the line, but
using our knowledge of ``^'' and ``$''.
But the easiest way uses the ``&'':
This says ``match the whole line, and replace it
by itself surrounded by parens.''~
The ``&'' can be used several times in a line;
Now is the time? Now is the time!!
We don't have to match the whole line, of course:
the end of the world is at hand
Observe this expression carefully,
for it illustrates how to take advantage of
the shorthand ``//'' found the same
and the ``&'' saved us from typing it again.
The ``&'' is a special character only within
the replacement text of a substitute command,
and has no special meaning elsewhere.
We can turn off the special meaning of ``&''
by preceding it with a ``\\'':
will convert the word ``ampersand'' into the literal symbol