useless.) But it does not call @code{search-forward} right away. First
it checks the next input character to see if is @kbd{C-w},
which specifies a word search.
-@ifinfo
+@ifnottex
@xref{Word Search}.
-@end ifinfo
+@end ifnottex
@kbd{C-r @key{RET}} does likewise, for a reverse incremental search.
@findex search-forward
special constructs and the rest are @dfn{ordinary}. An ordinary
character is a simple regular expression which matches that same
character and nothing else. The special characters are @samp{$},
-@samp{^}, @samp{.}, @samp{*}, @samp{+}, @samp{?}, @samp{[}, @samp{]} and
-@samp{\}. Any other character appearing in a regular expression is
-ordinary, unless a @samp{\} precedes it. (When you use regular
-expressions in a Lisp program, each @samp{\} must be doubled, see the
-example near the end of this section.)
+@samp{^}, @samp{.}, @samp{*}, @samp{+}, @samp{?}, @samp{[}, and
+@samp{\}. The character @samp{]} is special if it ends a character
+alternative (see later). The character @samp{-} is special inside a
+character alternative. Any other character appearing in a regular
+expression is ordinary, unless a @samp{\} precedes it. (When you use
+regular expressions in a Lisp program, each @samp{\} must be doubled,
+see the example near the end of this section.)
For example, @samp{f} is not a special character, so it is ordinary, and
therefore @samp{f} is a regular expression that matches the string
to depend on this behavior; it is better to quote the special character anyway,
regardless of where it appears.
+As a @samp{\} is not special inside a character alternative, it can
+never remove the special meaning of @samp{-} or @samp{]}. So you
+should not quote these characters when they have no special meaning
+either. This would not clarify anything, since backslashes can
+legitimately precede these characters where they @emph{have} special
+meaning, as in @samp{[^\]} (@code{"[^\\]"} for Lisp string syntax),
+which matches any single character except a backslash.
+
@node Regexp Backslash
@section Backslash in Regular Expressions
you can't refer back to it with @samp{\@var{d}}. This is useful
in mechanically combining regular expressions, so that you
can add groups for syntactic purposes without interfering with
-the numbering of the groups that were written by the user.
+the numbering of the groups that are meant to be referred to.
@item \@var{d}
+@cindex back reference, in regexp
matches the same text that matched the @var{d}th occurrence of a
-@samp{\( @dots{} \)} construct.
+@samp{\( @dots{} \)} construct. This is called a @dfn{back
+reference}.
After the end of a @samp{\( @dots{} \)} construct, the matcher remembers
the beginning and end of the text matched by that construct. Then,
Replace every match for @var{regexp} with @var{newstring}.
@end table
+@cindex back reference, in regexp replacement
In @code{replace-regexp}, the @var{newstring} need not be constant:
it can refer to all or part of what is matched by the @var{regexp}.
@samp{\&} in @var{newstring} stands for the entire match being
replaced. @samp{\@var{d}} in @var{newstring}, where @var{d} is a
digit, stands for whatever matched the @var{d}th parenthesized
-grouping in @var{regexp}. @samp{\#} refers to the count of
-replacements already made in this command, as a decimal number. In
-the first replacement, @samp{\#} stands for @samp{0}; in the second,
-for @samp{1}; and so on. For example,
+grouping in @var{regexp}. (This is called a ``back reference''.)
+@samp{\#} refers to the count of replacements already made in this
+command, as a decimal number. In the first replacement, @samp{\#}
+stands for @samp{0}; in the second, for @samp{1}; and so on. For
+example,
@example
M-x replace-regexp @key{RET} c[ad]+r @key{RET} \&-safe @key{RET}
@item M-x multi-occur-in-matching-buffers @key{RET} @var{bufregexp} @key{RET} @var{regexp} @key{RET}
This function is similar to @code{multi-occur}, except the buffers to
search are specified by a regular expression that matches visited
-filenames. With a prefix argument, it uses the regular expression to match
+file names. With a prefix argument, it uses the regular expression to match
buffer names instead.
@item M-x how-many @key{RET} @var{regexp} @key{RET}