[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Regarding replacing regexp
From: |
Barry Margolin |
Subject: |
Re: Regarding replacing regexp |
Date: |
Thu, 10 May 2012 23:10:40 -0400 |
User-agent: |
MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) |
In article <mailman.942.1336705240.855.help-gnu-emacs@gnu.org>,
XeCycle <XeCycle@Gmail.com> wrote:
> Deniz Dogan <deniz@dogan.se> writes:
>
> > On 2012-05-10 11:37, shirish wrote:
> >> Hi,
> >>
> >> I am in the process of learning how to use emacs. I know about the
> >> replace-regexp but I am unable to create a regular expression to do the
> >> below.
> >> Any help is much appreciated.
> >>
> >> public static final String SUCCESS //Successmesg
> >> public static final String FAILURE //failuremessage
> >>
> >> I need to replace that with
> >>
> >> public static final String SUCCESS = "SUCCESS";//Successmesg
> >> public static final String FAILURE = "FAILURE"; //failuremessage
> >>
> >> Thanks,
> >> Shirish.
> >>
> >>
> >
> > 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?
>
> 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.
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.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***