comparison man/lispref/searching.texi @ 2255:03d9d549c3fa

[xemacs-hg @ 2004-09-08 10:32:50 by stephent] update for shy groups <87zn41uk4j.fsf@tleepslib.sk.tsukuba.ac.jp>
author stephent
date Wed, 08 Sep 2004 10:32:55 +0000
parents c3cf7db99b98
children f45ce138f2ad
comparison
equal deleted inserted replaced
2254:cf4470caf504 2255:03d9d549c3fa
444 444
445 @item \@var{digit} 445 @item \@var{digit}
446 matches the same text that matched the @var{digit}th occurrence of a 446 matches the same text that matched the @var{digit}th occurrence of a
447 @samp{\( @dots{} \)} construct. 447 @samp{\( @dots{} \)} construct.
448 448
449 In other words, after the end of a @samp{\( @dots{} \)} construct. the 449 In other words, after the end of a @samp{\( @dots{} \)} construct, the
450 matcher remembers the beginning and end of the text matched by that 450 matcher remembers the beginning and end of the text matched by that
451 construct. Then, later on in the regular expression, you can use 451 construct. Then, later on in the regular expression, you can use
452 @samp{\} followed by @var{digit} to match that same text, whatever it 452 @samp{\} followed by @var{digit} to match that same text, whatever it
453 may have been. 453 may have been.
454 454
471 substring to be recorded for future reference. 471 substring to be recorded for future reference.
472 472
473 This is useful when you need a lot of grouping @samp{\( @dots{} \)} 473 This is useful when you need a lot of grouping @samp{\( @dots{} \)}
474 constructs, but only want to remember one or two -- or if you have 474 constructs, but only want to remember one or two -- or if you have
475 more than nine groupings and need to use backreferences to refer to 475 more than nine groupings and need to use backreferences to refer to
476 the groupings at the end. 476 the groupings at the end. It also allows construction of regular
477 477 expressions from variable subexpressions that contain varying numbers of
478 Using @samp{\(?: @dots{} \)} rather than @samp{\( @dots{} \)} when you 478 non-capturing subexpressions, without disturbing the group counts for
479 don't need the captured substrings ought to speed up your programs some, 479 the main expression. For example
480 since it shortens the code path followed by the regular expression 480
481 engine, as well as the amount of memory allocation and string copying it 481 @example
482 must do. The actual performance gain to be observed has not been 482 (let ((sre (if foo "\\(?:bar\\|baz\\)" "quux")))
483 measured or quantified as of this writing. 483 (re-search-forward (format "a\\(b+ %s c+\\) d" sre) nil t)
484 @c This is used to good advantage by the font-locking code, and by 484 (match-string 1))
485 @c `regexp-opt.el'. 485 @end example
486 486
487 The shy grouping operator has been borrowed from Perl, and has not been 487 It is very tedious to write this kind of code without shy groups, even
488 available prior to XEmacs 20.3, nor is it available in FSF Emacs. 488 if you know what all the alternative subexpressions will look like.
489
490 Using @samp{\(?: @dots{} \)} rather than @samp{\( @dots{} \)} should
491 give little performance gain, as the start of each group must be
492 recorded for the purpose of back-tracking in any case, and no string
493 copying is done until @code{match-string} is called.
494
495 The shy grouping operator has been borrowed from Perl, and was not
496 available prior to XEmacs 20.3, and has only been available in GNU Emacs
497 since version 21.
489 498
490 @item \w 499 @item \w
491 @cindex @samp{\w} in regexp 500 @cindex @samp{\w} in regexp
492 matches any word-constituent character. The editor syntax table 501 matches any word-constituent character. The editor syntax table
493 determines which characters these are. @xref{Syntax Tables}. 502 determines which characters these are. @xref{Syntax Tables}.