emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What is the difference between looking-at and an anchored search?


From: David Kastrup
Subject: Re: What is the difference between looking-at and an anchored search?
Date: Thu, 17 Jul 2008 14:33:33 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)

Miles Bader <address@hidden> writes:

> "Lennart Borgman (gmail)" <address@hidden> writes:
>> looking-at does not have a BOUND parameter, but re-search-forward
>> have. This makes re-search-forward a bit more flexible.
>>
>> I am looking at some code where I would have use for that flexibility,
>> but I wonder if there is any drawback with replacing looking-at with
>> re-search-forward (with an achored pattern).
>>
>> Is there any? Performance?
>
> If you want to reject matches that extend past some point, just do
> something like:
>
>    (and (looking-at REGEXP) (<= (match-end 0) BOUND))

That is not the same.

(with-temp-buffer (insert "abc")
  (goto-char 1)
  (list
    (re-search-forward ".*" 2)
    (progn (goto-char 1)
      (and (looking-at ".*") (<= (match-end 0) 2)))))

=> (2 nil)

-- 
David Kastrup




reply via email to

[Prev in Thread] Current Thread [Next in Thread]