From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: XeCycle Newsgroups: gmane.emacs.help Subject: Re: Regarding replacing regexp Date: Fri, 11 May 2012 11:52:40 +0800 Message-ID: <87zk9fpe5z.fsf@xc.laptop> References: <4FABEC39.6060305@dogan.se> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" X-Trace: dough.gmane.org 1336708546 15898 80.91.229.3 (11 May 2012 03:55:46 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 11 May 2012 03:55:46 +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:55:45 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 1SSgxF-0001ub-CE for geh-help-gnu-emacs@m.gmane.org; Fri, 11 May 2012 05:55:45 +0200 Original-Received: from localhost ([::1]:33482 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SSgxE-0006dJ-L4 for geh-help-gnu-emacs@m.gmane.org; Thu, 10 May 2012 23:55:44 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:43924) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SSgx8-0006dD-Gd for help-gnu-emacs@gnu.org; Thu, 10 May 2012 23:55:39 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SSgx6-00023C-Lr for help-gnu-emacs@gnu.org; Thu, 10 May 2012 23:55:38 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:43366) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SSgx6-000234-Es for help-gnu-emacs@gnu.org; Thu, 10 May 2012 23:55:36 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1SSgwy-0001lY-C6 for help-gnu-emacs@gnu.org; Fri, 11 May 2012 05:55:28 +0200 Original-Received: from 59.78.37.25 ([59.78.37.25]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 11 May 2012 05:55:28 +0200 Original-Received: from XeCycle by 59.78.37.25 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 11 May 2012 05:55:28 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 74 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: 59.78.37.25 User-Agent: Gnus/5.130006 (Ma Gnus v0.6) Emacs/24.1.50 (gnu/linux) Cancel-Lock: sha1:YNmP7BGVfqEtss/6HPDwkbAmwTk= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 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:84804 Archived-At: --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Barry Margolin writes: [...] >> > There are a lot of ways to do it. One could be: >> > >> > String \([^ ]+\) >> > >> > and replace it with: >> > >> > String \1 =3D "\1" >>=20 >> 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. >>=20 >> Try: >>=20 >> SUCCESS\|FAILURE =3D> \& =3D "\&"; >>=20 >> I may be wrong about those escapes, try it. > > You're assuming those are the only names he has to replace. The first=20 > 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= =20 > 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. =2D-=20 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 --=-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (GNU/Linux) iQEcBAEBAgAGBQJPrI0LAAoJEI1xjsR3leWRIC4IAMSCFDd3X4xqTbJP8urm5A30 VXGQwBk+tV/JsZ9xBvfsNrNLlR15IO9tgHXOm5ZqI44wn0PpZ/5hTLDgzmNqA89v VhifnuPHIqytl7/gwCwNa3DmDkI0j7FqIdpZ75onPoEivjkZDjrdeB2sXfZ44FKt R2hhU2/bzy0mA0r2llk2CQn+7y4k8Pwz+DwHbMjjZbF57qbs2/j9EkH6CWVsON9/ WZ37L4F8haMNoI+HNoMwYLBRgB8EicV/vt3HckbEOXcW5vKCkT4aU5FVljVzL/1j 54a5BiLD7w6/7p+5u5dTuJBEadxu9yznXu1FM49NUS6h3Sj8VnLLFtCnQ02ixKs= =WM/4 -----END PGP SIGNATURE----- --=-=-=--