help-emacs-windows
[Top][All Lists]
Advanced

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

Re: [h-e-w] RegExp in


From: Tom Capey
Subject: Re: [h-e-w] RegExp in
Date: 15 Sep 2004 15:55:10 +0100
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50

* Slava <address@hidden> writes:

> Hi, All,
> I need your help!

> Next code doesn't search anything. Why?

> (defun my-function ()
>       "Replace  '%' with '\%' (it should skip percent signs already
>       with the slash"
>       (interactive)
>       (while (re-search-forward "\([^\\]\)%" nil t)   
>               (replace-match "\1%" nil nil)))

> It works without '\(...\)', but then I loose one symbol before each percent
> sign being replaced. 


  double up the slashes to add them before the percentage sign
  (and double them up in the search expression).


(defun my-function ()
  "Replace  '%' with '\%' (it should skip percent signs already with the slash"
  (interactive)
  (while (re-search-forward "\\([^\\]\\)%" nil t)
    (replace-match "\\1\\\\%")))

     


/Tom
-- 
I for one welcome our new key-chord-requiring self-documenting
extensible OS-in-an-editor Emacs overlord. -- Jock Cooper



--- Disclaimer ---

Unless otherwise agreed expressly in writing by a Director of Edina Software, 
this communication is to be treated as confidential and the information in it 
may not be used or disclosed except for the purpose for which it has been sent. 
If you have reason to believe that you are not the intended recipient of this 
communication, please contact the sender immediately. 




reply via email to

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