From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: tyler Newsgroups: gmane.emacs.help 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 Message-ID: <87skpck6jd.fsf@blackbart.sedgenet> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1227834128 29055 80.91.229.12 (28 Nov 2008 01:02:08 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 28 Nov 2008 01:02:08 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Nov 28 02:03:11 2008 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1L5rlE-0003G8-Sk for geh-help-gnu-emacs@m.gmane.org; Fri, 28 Nov 2008 02:03:09 +0100 Original-Received: from localhost ([127.0.0.1]:35524 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L5rk5-0002UF-8M for geh-help-gnu-emacs@m.gmane.org; Thu, 27 Nov 2008 20:01:57 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1L5rjm-0002Tl-Bx for help-gnu-emacs@gnu.org; Thu, 27 Nov 2008 20:01:38 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1L5rjl-0002T9-Fd for help-gnu-emacs@gnu.org; Thu, 27 Nov 2008 20:01:38 -0500 Original-Received: from [199.232.76.173] (port=58759 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L5rjl-0002T6-Cy for help-gnu-emacs@gnu.org; Thu, 27 Nov 2008 20:01:37 -0500 Original-Received: from main.gmane.org ([80.91.229.2]:36964 helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1L5rjk-0000Yc-RD for help-gnu-emacs@gnu.org; Thu, 27 Nov 2008 20:01:37 -0500 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1L5rje-0002Pi-Qo for help-gnu-emacs@gnu.org; Fri, 28 Nov 2008 01:01:30 +0000 Original-Received: from hlfxns0149w-142068241109.pppoe-dynamic.ns.aliant.net ([142.68.241.109]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 28 Nov 2008 01:01:30 +0000 Original-Received: from tyler.smith by hlfxns0149w-142068241109.pppoe-dynamic.ns.aliant.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 28 Nov 2008 01:01:30 +0000 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 53 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: hlfxns0149w-142068241109.pppoe-dynamic.ns.aliant.net User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) Cancel-Lock: sha1:Bsj02RU7dRPUCii4E7MCTZzns9Q= X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:60171 Archived-At: "Tim Visher" 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