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

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

Re: Utilizing Regexp (or something else) to replace an arbitrary string


From: Xah Lee
Subject: Re: Utilizing Regexp (or something else) to replace an arbitrary string length of the same character with the same string length of another character.
Date: Wed, 26 Nov 2008 09:25:56 -0800 (PST)
User-agent: G2/1.0

On Nov 26, 6:41 am, "Tim Visher" <tim.vis...@gmail.com> wrote:
> Hello Everyone,
>
> I have a bunch of arbitrarily long strings of '=' characters and I
> would like to replace them one for one with '-' characters.  I know I
> could do this with a simple find and replace using isearch, but that
> would require me going through them one at a time.  I'm wondering if
> there's a way to do this with a regex such as:
>
>     r/(=+)/-{length of n}
>
> Obviously that's a major bastardization of syntax and doesn't really
> exist in any language, but I figure this should be able to be done in
> Emacs somehow.

if your question is about interactive use, then you can use

query-replace
query-replace-regexp

after you type the find string and replace string, you can just type
“!” to replace them all in one shot in the current buffer.

If you don't want it to promp you on the first finding, you can call
replace-string instead.

If your question is about doing the replacement on whole directory of
files, you can mark the files in dired and then invoke dired-do-query-
replace-regexp.

See:

• Find and Replace with Emacs
  http://xahlee.org/emacs/emacs_find_replace.html

• Interactively Find and Replace String Patterns on Multiple Files
  http://xahlee.org/emacs/find_replace_inter.html

If your question is about writing a lisp program so that you can press
a button to do all the replacement you want without needing to answer
prompt bout find/replace string, on a single file or bunch of files,
it's very easy too. See for example:

• Elisp Lesson: Repeated Find Replace
  http://xahlee.org/emacs/elisp_repeat_replace.html

> In Christ,

• Has Religion Made Useful Contributions to Civilization?
  http://xahlee.org/p/religion_Russell.html

  Xah
∑ http://xahlee.org/

reply via email to

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