all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: XeCycle <XeCycle@Gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Regarding replacing regexp
Date: Fri, 11 May 2012 11:52:40 +0800	[thread overview]
Message-ID: <87zk9fpe5z.fsf@xc.laptop> (raw)
In-Reply-To: barmar-0DD135.23104010052012@news.eternal-september.org

[-- Attachment #1: Type: text/plain, Size: 1463 bytes --]

Barry Margolin <barmar@alum.mit.edu> writes:

[...]

>> > There are a lot of ways to do it.  One could be:
>> >
>> > String \([^ ]+\)
>> >
>> > and replace it with:
>> >
>> > String \1 = "\1"
>> 
>> This won't do very well.
>
> Except that he forgot the semicolon, what's wrong about it?

May match something more, of course; mine has the same problem.

>> 
>> Try:
>> 
>> SUCCESS\|FAILURE => \& = "\&";
>> 
>> I may be wrong about those escapes, try it.
>
> You're assuming those are the only names he has to replace.  The first 
> responder assumed that they were just examples of a common pattern.

Huh?  Don't know what the OP want, though.

> Plus, your version will replace them in other contexts, e.g. the program 
> is likely to contain something like:
>
> if (...) return SUCCESS;
>
> but you wouldn't want to change this with the replacement.

That's a common problem about such replacements.  Similarly one
may want to define a String object somewhere else, Deniz's
solution will fail, too.  Query replace to the rescue.  It's up
to the OP to decide which one will be better, or combine them to
remove more mismatches:

String \(SUCCESS\|FAILURE\)

Of course, those tools are rarely accurate in such things like
code refactoring.

-- 
Carl Lei (XeCycle)
Department of Physics, Shanghai Jiao Tong University
OpenPGP public key: 7795E591
Fingerprint: 1FB6 7F1F D45D F681 C845 27F7 8D71 8EC4 7795 E591

[-- Attachment #2: Type: application/pgp-signature, Size: 489 bytes --]

  reply	other threads:[~2012-05-11  3:52 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-10  9:37 Regarding replacing regexp shirish
2012-05-10 16:26 ` Deniz Dogan
2012-05-11  2:57   ` XeCycle
     [not found]   ` <mailman.942.1336705240.855.help-gnu-emacs@gnu.org>
2012-05-11  3:10     ` Barry Margolin
2012-05-11  3:52       ` XeCycle [this message]
2012-05-12 10:39   ` shirish
2012-05-11  8:39 ` Peter Dyballa
2012-05-12 10:39   ` shirish

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

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

  git send-email \
    --in-reply-to=87zk9fpe5z.fsf@xc.laptop \
    --to=xecycle@gmail.com \
    --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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.