comparison man/search.texi @ 44062:32211007711c

Clarify non-greedy repetition in searching.
author Richard M. Stallman <rms@gnu.org>
date Thu, 21 Mar 2002 09:37:22 +0000
parents feea30bbbf13
children 230b150398fa
comparison
equal deleted inserted replaced
44061:f816ded285dd 44062:32211007711c
460 Thus, both @samp{ab*} and @samp{ab*?} can match the string @samp{a} 460 Thus, both @samp{ab*} and @samp{ab*?} can match the string @samp{a}
461 and the string @samp{abbbb}; but if you try to match them both against 461 and the string @samp{abbbb}; but if you try to match them both against
462 the text @samp{abbb}, @samp{ab*} will match it all (the longest valid 462 the text @samp{abbb}, @samp{ab*} will match it all (the longest valid
463 match), while @samp{ab*?} will match just @samp{a} (the shortest 463 match), while @samp{ab*?} will match just @samp{a} (the shortest
464 valid match). 464 valid match).
465
466 Non-greedy operators match the shortest possible string starting at a
467 given starting point; in a forward search, though, the earliest
468 possible starting point for match is always the one chosen. Thus, if
469 you search for @samp{a.*?$} against the text @samp{abbab} followed by
470 a newline, it matches the whole string. Since it @emph{can} match
471 starting at the first @samp{a}, it does.
465 472
466 @item \@{@var{n}\@} 473 @item \@{@var{n}\@}
467 is a postfix operator that specifies repetition @var{n} times---that 474 is a postfix operator that specifies repetition @var{n} times---that
468 is, the preceding regular expression must match exactly @var{n} times 475 is, the preceding regular expression must match exactly @var{n} times
469 in a row. For example, @samp{x\@{4\@}} matches the string @samp{xxxx} 476 in a row. For example, @samp{x\@{4\@}} matches the string @samp{xxxx}