# HG changeset patch # User Richard M. Stallman # Date 1096385024 0 # Node ID a325c378e9bbccf9da6452b6e37659da8c2f0eb5 # Parent f4a2067d260e3ae71945396fbef310aa327085c8 (Regexp Search): Add looking-back. diff -r f4a2067d260e -r a325c378e9bb lispref/searching.texi --- a/lispref/searching.texi Mon Sep 27 22:45:37 2004 +0000 +++ b/lispref/searching.texi Tue Sep 28 15:23:44 2004 +0000 @@ -975,6 +975,32 @@ @end example @end defun +@defun looking-back regexp &optional limit +This function returns @code{t} if @var{regexp} matches text before +point, ending at point, and @code{nil} otherwise. + +Because regular expression matching works only going forward, this is +implemented by searching backwards from point for a match that ends at +point. That can be quite slow if it has to search a long distance. +You can bound the time required by specifying @var{limit}, which says +not to search before @var{limit}. In this case, the match that is +found must begin at or after @var{limit}. + +@example +@group +---------- Buffer: foo ---------- +I read "@point{}The cat in the hat +comes back" twice. +---------- Buffer: foo ---------- + +(looking-back "read \"" 3) + @result{} t +(looking-back "read \"" 4) + @result{} nil +@end group +@end example +@end defun + @node POSIX Regexps @section POSIX Regular Expression Searching