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

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

Re: (rx regexp to remove space and new lines


From: Jean Louis
Subject: Re: (rx regexp to remove space and new lines
Date: Mon, 12 Sep 2022 13:25:11 +0300
User-agent: Mutt/+ () (2022-06-11)

* tomas@tuxteam.de <tomas@tuxteam.de> [2022-09-12 13:15]:
> On Mon, Sep 12, 2022 at 12:25:58PM +0300, Jean Louis wrote:
> > I would like to construct rx regexp to remove both whitespace
> > characters and new line "\n" to replace it with only one space " ".
> > 
> > How to do it?
> > 
> > (string-replace (rx (one-or-more (any "\n" "[[:space:]]"))) " " sql)))))
> 
> This looks about correct, so I don't understand your question. In which way
> this does fail? Don't make us solve riddles ;-)

(replace-regexp-in-string (rx (one-or-more (any whitespace))) " "
"Hello    there

and    here") ⇒ "Hello there

and here"

new line is not removed with character class `whitespace'.

(replace-regexp-in-string (rx (one-or-more (or "\n" (any whitespace)))) " "
"Hello    there

and    here") ⇒ "Hello there and here"

So now it will work that way.

-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



reply via email to

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