Mercurial > emacs
comparison lispref/searching.texi @ 57252:a325c378e9bb
(Regexp Search): Add looking-back.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 28 Sep 2004 15:23:44 +0000 |
parents | 7cc505680b75 |
children | 5353c1a56ee3 e23928ac5a97 |
comparison
equal
deleted
inserted
replaced
57251:f4a2067d260e | 57252:a325c378e9bb |
---|---|
973 @result{} t | 973 @result{} t |
974 @end group | 974 @end group |
975 @end example | 975 @end example |
976 @end defun | 976 @end defun |
977 | 977 |
978 @defun looking-back regexp &optional limit | |
979 This function returns @code{t} if @var{regexp} matches text before | |
980 point, ending at point, and @code{nil} otherwise. | |
981 | |
982 Because regular expression matching works only going forward, this is | |
983 implemented by searching backwards from point for a match that ends at | |
984 point. That can be quite slow if it has to search a long distance. | |
985 You can bound the time required by specifying @var{limit}, which says | |
986 not to search before @var{limit}. In this case, the match that is | |
987 found must begin at or after @var{limit}. | |
988 | |
989 @example | |
990 @group | |
991 ---------- Buffer: foo ---------- | |
992 I read "@point{}The cat in the hat | |
993 comes back" twice. | |
994 ---------- Buffer: foo ---------- | |
995 | |
996 (looking-back "read \"" 3) | |
997 @result{} t | |
998 (looking-back "read \"" 4) | |
999 @result{} nil | |
1000 @end group | |
1001 @end example | |
1002 @end defun | |
1003 | |
978 @node POSIX Regexps | 1004 @node POSIX Regexps |
979 @section POSIX Regular Expression Searching | 1005 @section POSIX Regular Expression Searching |
980 | 1006 |
981 The usual regular expression functions do backtracking when necessary | 1007 The usual regular expression functions do backtracking when necessary |
982 to handle the @samp{\|} and repetition constructs, but they continue | 1008 to handle the @samp{\|} and repetition constructs, but they continue |