Minor cleanups.
[bpt/emacs.git] / lispref / searching.texi
index cc1a8c9..63e4611 100644 (file)
@@ -1,6 +1,7 @@
 @c -*-texinfo-*-
 @c This is part of the GNU Emacs Lisp Reference Manual.
-@c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998 Free Software Foundation, Inc. 
+@c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999
+@c   Free Software Foundation, Inc. 
 @c See the file elisp.texi for copying conditions.
 @setfilename ../info/searching
 @node Searching and Matching, Syntax Tables, Non-ASCII Characters, Top
@@ -310,16 +311,26 @@ matches both @samp{]} and @samp{-}.
 To include @samp{^} in a character alternative, put it anywhere but at
 the beginning.
 
-The beginning and end of a range must be in the same character set
-(@pxref{Character Sets}).  Thus, @samp{[a-\x8e0]} is invalid because
-@samp{a} is in the @sc{ascii} character set but the character 0x8e0
-(@samp{a} with grave accent) is in the Emacs character set for Latin-1.
+The beginning and end of a range of multibyte characters must be in
+the same character set (@pxref{Character Sets}).  Thus,
+@code{"[\x8e0-\x97c]"} is invalid because character 0x8e0 (@samp{a}
+with grave accent) is in the Emacs character set for Latin-1 but the
+character 0x97c (@samp{u} with diaeresis) is in the Emacs character
+set for Latin-2.  (We use Lisp string syntax to write that example,
+and a few others in the next few paragraphs, in order to include hex
+escape sequences in them.)
+
+If a range starts with a unibyte character @var{c} and ends with a
+multibyte character @var{c2}, the range is divided into two parts: one
+is @samp{@var{c}..?\377}, the other is @samp{@var{c1}..@var{c2}}, where
+@var{c1} is the first character of the charset to which @var{c2}
+belongs.
  
 You cannot always match all non-@sc{ascii} characters with the regular
-expression @samp{[\200-\377]}.  This works when searching a unibyte
+expression @code{"[\200-\377]"}.  This works when searching a unibyte
 buffer or string (@pxref{Text Representations}), but not in a multibyte
 buffer or string, because many non-@sc{ascii} characters have codes
-above octal 0377.  However, the regular expression @samp{[^\000-\177]}
+above octal 0377.  However, the regular expression @code{"[^\000-\177]"}
 does match all non-@sc{ascii} characters (see below regarding @samp{^}),
 in both multibyte and unibyte representations, because only the
 @sc{ascii} characters are excluded.
@@ -353,7 +364,7 @@ match anything.  Thus, @samp{^foo} matches a @samp{foo} that occurs at
 the beginning of a line.
 
 When matching a string instead of a buffer, @samp{^} matches at the
-beginning of the string or after a newline character @samp{\n}.
+beginning of the string or after a newline character.
 
 For historical compatibility reasons, @samp{^} can be used only at the
 beginning of the regular expression, or after @samp{\(} or @samp{\|}.
@@ -365,7 +376,7 @@ is similar to @samp{^} but matches only at the end of a line.  Thus,
 @samp{x+$} matches a string of one @samp{x} or more at the end of a line.
 
 When matching a string instead of a buffer, @samp{$} matches at the end
-of the string or before a newline character @samp{\n}.
+of the string or before a newline character.
 
 For historical compatibility reasons, @samp{$} can be used only at the
 end of the regular expression, or before @samp{\)} or @samp{\|}.
@@ -404,7 +415,7 @@ in Emacs 21, and what they mean:
 
 @table @samp
 @item [:ascii:]
-This matches any ASCII (unibyte) character.
+This matches any @sc{ascii} (unibyte) character.
 @item [:alnum:]
 This matches any letter or digit.  (At present, for multibyte
 characters, it matches anything that has word syntax.)
@@ -414,21 +425,21 @@ matches anything that has word syntax.)
 @item [:blank:]
 This matches space and tab only.
 @item [:cntrl:]
-This matches any ASCII control character.
+This matches any @sc{ascii} control character.
 @item [:digit:]
 This matches @samp{0} through @samp{9}.  Thus, @samp{[-+[:digit:]]}
 matches any digit, as well as @samp{+} and @samp{-}.
 @item [:graph:]
-This matches graphic characters---everything except ASCII control characters,
-space, and DEL.
+This matches graphic characters---everything except @sc{ascii} control
+characters, space, and the delete character.
 @item [:lower:]
 This matches any lower-case letter, as determined by
 the current case table (@pxref{Case Tables}).
 @item [:nonascii:]
-This matches any non-ASCII (multibyte) character.
+This matches any non-@sc{ascii} (multibyte) character.
 @item [:print:]
-This matches printing characters---everything except ASCII control
-characters and DEL.
+This matches printing characters---everything except @sc{ascii} control
+characters and the delete character.
 @item [:punct:]
 This matches any punctuation character.  (At present, for multibyte
 characters, it matches anything that has non-word syntax.)
@@ -476,6 +487,25 @@ Full backtracking capability exists to handle multiple uses of
 @samp{\|}, if you use the POSIX regular expression functions
 (@pxref{POSIX Regexps}).
 
+@item \@{@var{m}\@}
+is a postfix operator that repeats the previous pattern exactly @var{m}
+times.  Thus, @samp{x\@{5\@}} matches the string @samp{xxxxx}
+and nothing else.  @samp{c[ad]\@{3\@}r} matches string such as
+@samp{caaar}, @samp{cdddr}, @samp{cadar}, and so on.
+
+@item \@{@var{m},@var{n}\@}
+is more general postfix operator that specifies repetition with a
+minimum of @var{m} repeats and a maximum of @var{n} repeats.  If @var{m}
+is omitted, the minimum is 0; if @var{n} is omitted, there is no
+maximum.
+
+For example, @samp{c[ad]\@{1,2\@}r} matches the strings @samp{car},
+@samp{cdr}, @samp{caar}, @samp{cadr}, @samp{cdar}, and @samp{cddr}, and
+nothing else.@*
+@samp{\@{0,1\@}} or @samp{\@{,1\@}} is equivalent to @samp{?}. @*
+@samp{\@{0,\@}} or @samp{\@{,\@}} is equivalent to @samp{*}.   @*
+@samp{\@{1,\@}} is equivalent to @samp{+}.
+
 @item \( @dots{} \)
 @cindex @samp{(} in regexp
 @cindex @samp{)} in regexp
@@ -495,14 +525,26 @@ To enclose a complicated expression for the postfix operators @samp{*},
 number (zero or more) of @samp{na} strings.
 
 @item
-To record a matched substring for future reference.
+To record a matched substring for future reference with
+@samp{\@var{digit}} (see below).
 @end enumerate
 
 This last application is not a consequence of the idea of a
-parenthetical grouping; it is a separate feature that happens to be
-assigned as a second meaning to the same @samp{\( @dots{} \)} construct
-because there is no conflict in practice between the two meanings.
-Here is an explanation of this feature:
+parenthetical grouping; it is a separate feature that was assigned as a
+second meaning to the same @samp{\( @dots{} \)} construct because, in
+pratice, there was usually no conflict between the two meanings.  But
+occasionally there is a conflict, and that led to the introduction of
+shy groups.
+
+@item \(?: @dots{} \)
+is the @dfn{shy group} construct.  A shy group serves the first two
+purposes of an ordinary group (controlling the nesting of other
+operators), but it does not get a number, so you cannot refer back to
+its value with @samp{\@var{digit}}.
+
+Shy groups are particulary useful for mechanically-constructed regular
+expressions because they can be added automatically without altering the
+numbering of any ordinary, non-shy groups.
 
 @item \@var{digit}
 matches the same text that matched the @var{digit}th occurrence of a
@@ -546,6 +588,15 @@ the characters that stand for them.
 @item \S@var{code}
 @cindex @samp{\S} in regexp
 matches any character whose syntax is not @var{code}.
+
+@item \c@var{c}
+matches any character whose category is @var{c}.  Here @var{c} is a
+character that represents a category: thus, @samp{c} for Chinese
+characters or @samp{g} for Greek characters in the standard category
+table.
+
+@item \C@var{c}
+matches any character whose category is not @var{c}.
 @end table
 
   The following regular expression constructs match the empty string---that is,
@@ -1328,17 +1379,17 @@ position of the beginning of the match for the whole expression; element
 one is the position of the end of the match for the expression.  The
 next two elements are the positions of the beginning and end of the
 match for the first subexpression, and so on.  In general, element
-@ifinfo
+@ifnottex
 number 2@var{n}
-@end ifinfo
+@end ifnottex
 @tex
 number {\mathsurround=0pt $2n$}
 @end tex
 corresponds to @code{(match-beginning @var{n})}; and
 element
-@ifinfo
+@ifnottex
 number 2@var{n} + 1
-@end ifinfo
+@end ifnottex
 @tex
 number {\mathsurround=0pt $2n+1$}
 @end tex