* Regarding replacing regexp
@ 2012-05-10 9:37 shirish
2012-05-10 16:26 ` Deniz Dogan
2012-05-11 8:39 ` Peter Dyballa
0 siblings, 2 replies; 8+ messages in thread
From: shirish @ 2012-05-10 9:37 UTC (permalink / raw
To: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 459 bytes --]
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.
[-- Attachment #2: Type: text/html, Size: 770 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Regarding replacing regexp
2012-05-10 9:37 Regarding replacing regexp shirish
@ 2012-05-10 16:26 ` Deniz Dogan
2012-05-11 2:57 ` XeCycle
` (2 more replies)
2012-05-11 8:39 ` Peter Dyballa
1 sibling, 3 replies; 8+ messages in thread
From: Deniz Dogan @ 2012-05-10 16:26 UTC (permalink / raw
To: shirish; +Cc: help-gnu-emacs
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"
I would personally use keyboard macros for it.
I hope that helps,
Deniz
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Regarding replacing regexp
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-12 10:39 ` shirish
2 siblings, 0 replies; 8+ messages in thread
From: XeCycle @ 2012-05-11 2:57 UTC (permalink / raw
To: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 1148 bytes --]
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.
Try:
SUCCESS\|FAILURE => \& = "\&";
I may be wrong about those escapes, try it.
> I would personally use keyboard macros for it.
Yes, This would be fine, too. And usually easier than regexps.
--
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 --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Regarding replacing regexp
[not found] ` <mailman.942.1336705240.855.help-gnu-emacs@gnu.org>
@ 2012-05-11 3:10 ` Barry Margolin
2012-05-11 3:52 ` XeCycle
0 siblings, 1 reply; 8+ messages in thread
From: Barry Margolin @ 2012-05-11 3:10 UTC (permalink / raw
To: help-gnu-emacs
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 ***
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Regarding replacing regexp
2012-05-11 3:10 ` Barry Margolin
@ 2012-05-11 3:52 ` XeCycle
0 siblings, 0 replies; 8+ messages in thread
From: XeCycle @ 2012-05-11 3:52 UTC (permalink / raw
To: help-gnu-emacs
[-- 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 --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Regarding replacing regexp
2012-05-10 9:37 Regarding replacing regexp shirish
2012-05-10 16:26 ` Deniz Dogan
@ 2012-05-11 8:39 ` Peter Dyballa
2012-05-12 10:39 ` shirish
1 sibling, 1 reply; 8+ messages in thread
From: Peter Dyballa @ 2012-05-11 8:39 UTC (permalink / raw
To: shirish; +Cc: help-gnu-emacs
Am 10.05.2012 um 11:37 schrieb shirish:
> 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
You could try:
\(final \w+ \)\([A-Z]+\) -> \1\2 = "\2";
The text "final <some word> " followed by a sequence of upper-case letters (\([A-Z]+\)) is found and saved in registers and substituted with the first finding followed by '=' and the found sequence of upper-case letters in double quotation marks followed by ';'. The remainder of the original line stays unchanged.
--
Greetings
Pete
One cannot live by television, video games, top ten CDs, and dumb movies alone.
– Amiri Baraka, 1999
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Regarding replacing regexp
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-12 10:39 ` shirish
2 siblings, 0 replies; 8+ messages in thread
From: shirish @ 2012-05-12 10:39 UTC (permalink / raw
To: Deniz Dogan; +Cc: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 842 bytes --]
Thanks Demiz.
On Thu, May 10, 2012 at 9:56 PM, Deniz Dogan <deniz@dogan.se> wrote:
> 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"
>
> I would personally use keyboard macros for it.
>
> I hope that helps,
> Deniz
>
[-- Attachment #2: Type: text/html, Size: 1445 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Regarding replacing regexp
2012-05-11 8:39 ` Peter Dyballa
@ 2012-05-12 10:39 ` shirish
0 siblings, 0 replies; 8+ messages in thread
From: shirish @ 2012-05-12 10:39 UTC (permalink / raw
To: Peter Dyballa; +Cc: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 1031 bytes --]
Thanks Peter
On Fri, May 11, 2012 at 2:09 PM, Peter Dyballa <Peter_Dyballa@web.de> wrote:
>
> Am 10.05.2012 um 11:37 schrieb shirish:
>
> > 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
>
> You could try:
>
> \(final \w+ \)\([A-Z]+\) -> \1\2 = "\2";
>
> The text "final <some word> " followed by a sequence of upper-case letters
> (\([A-Z]+\)) is found and saved in registers and substituted with the first
> finding followed by '=' and the found sequence of upper-case letters in
> double quotation marks followed by ';'. The remainder of the original line
> stays unchanged.
>
> --
> Greetings
>
> Pete
>
> One cannot live by television, video games, top ten CDs, and dumb movies
> alone.
> – Amiri Baraka, 1999
>
>
[-- Attachment #2: Type: text/html, Size: 1506 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2012-05-12 10:39 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2012-05-12 10:39 ` shirish
2012-05-11 8:39 ` Peter Dyballa
2012-05-12 10:39 ` shirish
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.