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

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

Re: Another replace regexp with list question


From: WJ
Subject: Re: Another replace regexp with list question
Date: 5 Nov 2013 00:21:36 GMT
User-agent: XanaNews/1.18.1.6

Barry Margolin wrote:

> In article <address@hidden>,
>  Leandro Marcolino <address@hidden> wrote:
> 
> > Hello, everyone!..
> > 
> > This time I am trying to find occurrences of:
> > 
> > "<span style='color:white'>&#31169;&#31169;&#31169;&#31169;</span>", but
> > the number of &#31169; can change from 1 to many.
> > 
> > And I want to replace each &#31169; of the list to a white space (besides
> > removing the <span> clause). So, if there were x "&#31169;", I need x " ".
> > Is it possible to do this using replace-regexp?.. Of course I can't just
> > look for "&#31169;" and replace to " ", because I have occurrences of
> > "&#31169;" that are not inside the group "<span
> > style='color:white'></span>".
> > 
> > I tried something like "<span style='color:white'>\(\(&#31169;\)+\)</span>
> > -> \,(cond (\1 " ")))", but then I lose the information of how many
> > "&#31169;" were there, and everything changes to a single " "....
> > 
> > Thanks for your help!.. :)
> > 
> > Regards,
> > Leandro
> 
> Regular expressions can't count.
> 
> I would do it with a keyboard macro. Search for the span, mark it as a 
> region, narrow to region, use replace-string to replace each &#31169 
> with space, widen.

(replace-regexp-in-string
  "<span>\\(&#31169;\\)+</span>"
  (lambda (s)
    (make-string
      (length (replace-regexp-in-string "[^&]" "" s))
      ? ))
  "&#31169; hi<span>&#31169;&#31169;</span>there &#31169;")

  ===>

"&#31169; hi  there &#31169;"


reply via email to

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