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

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

Re: Regexp replacement question


From: Joost Kremers
Subject: Re: Regexp replacement question
Date: 23 Apr 2015 10:09:17 GMT
User-agent: slrn/pre1.0.0-18 (Linux)

EN:SiS(9)
MBR wrote:
> But what do I do if I want to replace leading zeroes with the same 
> number of spaces.  E.G. if my file contains:
[...]
> Ideas?

AFAIK "regular" regular expressions (pardon the pun) won't allow you to
do this. But at least with `replace-regexp' you can use Elisp
expressions in your replacement string, something like (untested):

M-x replace-regexp RET ^0+ RET
\,(make-string (length \&) " ")

Here, \& refers to the whole match. You can also use \1, \2, etc. to
refer to submatches.

IIUC such constructs aren't possible when the search/replace isn't
interactive, though.


HTH

-- 
Joost Kremers                                   address@hidden
Selbst in die Unterwelt dringt durch Spalten Licht


reply via email to

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