From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Orivej Desh Newsgroups: gmane.emacs.help Subject: Re: [2nd attempt] What's the doc of replace-regexp-in-string saying ? Date: Mon, 22 Nov 2010 21:32:09 +0300 Organization: A noiseless patient Spider Message-ID: References: <09bb11dd-b588-4b5c-8f8c-b31e2590599c@v23g2000vbi.googlegroups.com> <5a2270e2-889f-4d22-ba15-951a4c170671@o2g2000vbh.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: dough.gmane.org 1291949054 19309 80.91.229.12 (10 Dec 2010 02:44:14 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 10 Dec 2010 02:44:14 +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 Dec 10 03:44:10 2010 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PQsxt-0000AC-2B for geh-help-gnu-emacs@m.gmane.org; Fri, 10 Dec 2010 03:44:09 +0100 Original-Received: from localhost ([127.0.0.1]:49980 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PQsxs-0007tn-H3 for geh-help-gnu-emacs@m.gmane.org; Thu, 09 Dec 2010 21:44:08 -0500 Original-Path: usenet.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!news2.euro.net!feeder.news-service.com!85.214.198.2.MISMATCH!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help,comp.emacs,comp.unix.shell Original-Followup-To: comp.emacs Original-Lines: 51 Injection-Info: mx02.eternal-september.org; posting-host="pLVWFSHUtbwz7c6wuYx/TQ"; logging-data="15370"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/5Q2QJP7F1o1GqzS5eLTz/" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) Cancel-Lock: sha1:c93w/GVW8PIjhEVMYavFT29j+RQ= sha1:7niikHVvu3bpa0oZhzYt8Og6Ukc= Original-Xref: usenet.stanford.edu gnu.emacs.help:182580 comp.emacs:100819 comp.unix.shell:248537 X-Mailman-Approved-At: Thu, 09 Dec 2010 20:09:21 -0500 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:77220 Archived-At: Bill Marcum writes: > On 2010-11-22, bolega wrote: >> >> On Nov 21, 3:27 pm, bolega wrote: >>> Hello All, >>> >>> In this doc, its not clear what the role of \' is ? >>> >>> >>> To replace only the first match (if any), make REGEXP match up to \' >>> and replace a sub-expression, e.g. >>>   (replace-regexp-in-string "\(foo\).*\'" "bar" " foo foo" nil nil 1) >>>     => " bar foo" >> > This is off topic for comp.unix.shell, but it seems clear to me. If the > regexp didn't end with \', it would change " foo foo" to " bar bar". Since matching is hungry, this is not the case: (replace-regexp-in-string "\\(foo\\).*\\'" "bar" " foo foo" nil nil 1) " bar foo" (replace-regexp-in-string "\\(foo\\).*" "bar" " foo foo" nil nil 1) " bar foo" Moreover, I'm sure bolega has spotted an error in documentation. Consider this: (replace-regexp-in-string "\\(foo\\).*\\'" "bar" "foo foo\n foo foo" nil nil 1) "foo foo bar foo" Documentation string assumed that `.' would match a newline. \' matches an end of a string, unlike $ which matches both an end of a string and an end of a line). Without \' or with $ the last regexp matches twice: (replace-regexp-in-string "\\(foo\\).*" "bar" "foo foo\n foo foo" nil nil 1) "bar foo bar foo" (replace-regexp-in-string "\\(foo\\).*$" "bar" "foo foo\n foo foo" nil nil 1) "bar foo bar foo"