unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: tyler <tyler.smith@mail.mcgill.ca>
To: help-gnu-emacs@gnu.org
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: Thu, 27 Nov 2008 21:01:26 -0400	[thread overview]
Message-ID: <87skpck6jd.fsf@blackbart.sedgenet> (raw)
In-Reply-To: c115fd3c0811271224y3260d26eo4345c43ab141dff8@mail.gmail.com

"Tim Visher" <tim.visher@gmail.com> writes:

> Yeah, I did consider using replace-string and query-replace-string and
> their ilk.  The issue is that I use the characters I want to replace
> at other locations where I don't want them replaced.  Also, I want to
> replace an arbitrary amount of them at one time.  I actually already
> did the edits that I want done by using query-replace-string.
> However, if the document had been much longer, that really would've
> taken too long.  It doesn't sound like there's a quick way to do this
> in Emacs.  Oh well.
>

This brings to mind the old chestnut:

  Some people, when confronted with a problem, think "I know, I’ll use
  regular expressions." Now they have two problems. --Jamie Zawinski

Evaluate the following (C-x C-e with point after the final ')' ), then
call it with `M-x switcheroo' when point is before the sample text below.
It solves your problem, as I understand it. 


(defun switcheroo ()
  "Replaces multiple consecutive '=' chars with the same number of '*'.
Single '=' are left unmolested"
  (interactive)
  (save-excursion
    (while (search-forward "=")
      (if (looking-at "=")
	  (progn (backward-char 1)
		 (while (looking-at "=")
		   (delete-char 1)
		   (insert "*")))))))

  
==========asdf;lkj asdf= asdflkj = asdf
asflkj ==asdfa;lkj 
aslkj ===as;fl;kj =====asd;flkj 
as;dlfkja sd=============
asdf=asdflkj=asdfas=

=asdf=asdf=
==========================


HTH,

Tyler

-- 
There is something fascinating about science. One gets such wholesale 
returns of conjecture out of such a trifling investment of fact.
                                       --Mark Twain





  parent reply	other threads:[~2008-11-28  1:01 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.1299.1227715545.26697.help-gnu-emacs@gnu.org>
2008-11-26 17:25 ` Utilizing Regexp (or something else) to replace an arbitrary string length of the same character with the same string length of another character Xah Lee
2008-11-27 20:24   ` Tim Visher
2008-11-27 23:23     ` Peter Dyballa
     [not found]     ` <mailman.1392.1227828233.26697.help-gnu-emacs@gnu.org>
2008-11-28  0:01       ` Andreas Politz
2008-11-28  1:01     ` tyler [this message]
2008-11-26 14:41 Tim Visher
2008-11-26 16:31 ` Peter Dyballa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87skpck6jd.fsf@blackbart.sedgenet \
    --to=tyler.smith@mail.mcgill.ca \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).