X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=man%2Flispref%2Fsearching.texi;h=4f82114e8b0825a4426b34979d57ffc2aa4666ed;hb=c1fa38c050ef3bd87e784dea66eba3cdac585536;hp=22df2d735ffeb05bf15b41db2d6660afb361c798;hpb=82f6d62ee211b1d36e8f45fed3ee3edde82b6916;p=chise%2Fxemacs-chise.git.1 diff --git a/man/lispref/searching.texi b/man/lispref/searching.texi index 22df2d7..4f82114 100644 --- a/man/lispref/searching.texi +++ b/man/lispref/searching.texi @@ -446,7 +446,7 @@ Here is an explanation of this feature: matches the same text that matched the @var{digit}th occurrence of a @samp{\( @dots{} \)} construct. -In other words, after the end of a @samp{\( @dots{} \)} construct. the +In other words, after the end of a @samp{\( @dots{} \)} construct, the matcher remembers the beginning and end of the text matched by that construct. Then, later on in the regular expression, you can use @samp{\} followed by @var{digit} to match that same text, whatever it @@ -473,19 +473,28 @@ substring to be recorded for future reference. This is useful when you need a lot of grouping @samp{\( @dots{} \)} constructs, but only want to remember one or two -- or if you have more than nine groupings and need to use backreferences to refer to -the groupings at the end. +the groupings at the end. It also allows construction of regular +expressions from variable subexpressions that contain varying numbers of +non-capturing subexpressions, without disturbing the group counts for +the main expression. For example -Using @samp{\(?: @dots{} \)} rather than @samp{\( @dots{} \)} when you -don't need the captured substrings ought to speed up your programs some, -since it shortens the code path followed by the regular expression -engine, as well as the amount of memory allocation and string copying it -must do. The actual performance gain to be observed has not been -measured or quantified as of this writing. -@c This is used to good advantage by the font-locking code, and by -@c `regexp-opt.el'. +@example +(let ((sre (if foo "\\(?:bar\\|baz\\)" "quux"))) + (re-search-forward (format "a\\(b+ %s c+\\) d" sre) nil t) + (match-string 1)) +@end example + +It is very tedious to write this kind of code without shy groups, even +if you know what all the alternative subexpressions will look like. -The shy grouping operator has been borrowed from Perl, and has not been -available prior to XEmacs 20.3, nor is it available in FSF Emacs. +Using @samp{\(?: @dots{} \)} rather than @samp{\( @dots{} \)} should +give little performance gain, as the start of each group must be +recorded for the purpose of back-tracking in any case, and no string +copying is done until @code{match-string} is called. + +The shy grouping operator has been borrowed from Perl, and was not +available prior to XEmacs 20.3, and has only been available in GNU Emacs +since version 21. @item \w @cindex @samp{\w} in regexp @@ -507,6 +516,19 @@ 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{category} +@cindex @samp{\c} in regexp +matches any character in @var{category}. Only available under Mule, +categories, and category tables, are further described in @ref{Category +Tables}. They are a mechanism for constructing classes of characters +that can be local to a buffer, and that do not require complicated [] +expressions every time they are referenced. + +@item \C@var{category} +@cindex @samp{\C} in regexp +matches any character outside @var{category}. @xref{Category Tables}, +again, and note that this is only available under Mule. @end table The following regular expression constructs match the empty string---that is,