From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Barry Margolin Newsgroups: gmane.emacs.help Subject: Re: Regarding replacing regexp Date: Thu, 10 May 2012 23:10:40 -0400 Organization: A noiseless patient Spider Message-ID: References: <4FABEC39.6060305@dogan.se> NNTP-Posting-Host: plane.gmane.org X-Trace: dough.gmane.org 1336706120 2645 80.91.229.3 (11 May 2012 03:15:20 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 11 May 2012 03:15:20 +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 May 11 05:15:20 2012 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SSgK5-0008O0-4b for geh-help-gnu-emacs@m.gmane.org; Fri, 11 May 2012 05:15:17 +0200 Original-Received: from localhost ([::1]:59259 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SSgK4-0003ff-CI for geh-help-gnu-emacs@m.gmane.org; Thu, 10 May 2012 23:15:16 -0400 Original-Path: usenet.stanford.edu!goblin1!goblin.stu.neva.ru!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 59 Injection-Info: barmar.motzarella.org; posting-host="ePtxJaRXJPFeIWBMlKfZaA"; logging-data="22351"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+RbIoHMZQ1Mb4bIl79gDKj" User-Agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) Cancel-Lock: sha1:S7jL83LUdRYOhpDEnNTkaqlkW1M= Original-Xref: usenet.stanford.edu gnu.emacs.help:192396 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:84803 Archived-At: In article , XeCycle wrote: > Deniz Dogan 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 ***