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: Easy regexp issue Date: Fri, 19 Jan 2007 02:49:25 -0500 Organization: Symantec Message-ID: References: <1169145159.761299.289970@38g2000cwa.googlegroups.com> NNTP-Posting-Host: lo.gmane.org X-Trace: sea.gmane.org 1169196030 29812 80.91.229.12 (19 Jan 2007 08:40:30 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 19 Jan 2007 08:40:30 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Jan 19 09:40:28 2007 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.50) id 1H7pIS-00045t-2F for geh-help-gnu-emacs@m.gmane.org; Fri, 19 Jan 2007 09:40:28 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1H7pIR-0008CX-HV for geh-help-gnu-emacs@m.gmane.org; Fri, 19 Jan 2007 03:40:27 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!postnews.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail Original-NNTP-Posting-Date: Fri, 19 Jan 2007 01:49:26 -0600 Original-Newsgroups: gnu.emacs.help Mail-Copies-To: nobody User-Agent: MT-NewsWatcher/3.5.2 (PPC Mac OS X) X-Copies-To: never Original-Lines: 45 Original-NNTP-Posting-Host: 24.34.108.171 Original-X-Trace: sv3-SFuHOptlVfnO2pQU+XnMqTlC/NSDJta3XsWYzunFJUso3d0S/utb/0RZ/PwWppGJ8YEpcgHRqLfCEWK!LNb8M8sBjlUz/ee0RsZ9YaWmz/Z9KMxK0sWslIwQtVNuxwCHsT5mkf+EUZudytytcoaTtxtFCI+2!Ss77BY7FBdGbnFA4YcJ5dr+OMU5PPw7KSg== Original-X-Complaints-To: abuse@comcast.net X-DMCA-Complaints-To: dmca@comcast.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.32 Original-Xref: shelby.stanford.edu gnu.emacs.help:144848 Original-To: help-gnu-emacs@gnu.org 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:40453 Archived-At: In article , Kevin Rodgers wrote: > HS wrote: > > I'm finding this quite odd: > > I want to replace all slashes for backslashes in a string, but i'm > > having trouble! > > > > Running this: > > (replace-regexp-in-string "/" "\\" "c:/emacs/lisp/") > > I get: > > Debugger entered--Lisp error: (error "Invalid use of `\\' in > > replacement text") > > > > And if I try: > > (replace-regexp-in-string "/" "\" "c:/emacs/lisp/") > > I get: > > Debugger entered--Lisp error: (scan-error "Unbalanced parentheses" 302 > > 1) > > > > So, I don't see any other options! > > I know the problems is there because I replace for another string then > > it works: > > (replace-regexp-in-string "/" "x" "c:/emacs/lisp/") > > "c:xemacsxlispx" > > See the LITERAL argument in the doc string for replace-regexp-in-string: > > (replace-regexp-in-string "/" "\\" "c:/emacs/lisp/" nil t) Or (replace-regexp-in-string "/" "\\\\" "c:/emacs/lisp/") This is necessary because backslash is an escape character at two levels: Lisp strings and regexp replacement strings (e.g. the sequence \1 in the replacement represents a group matched in the regexp). So the replacement string needs to be \\, and you need to escape each \ in the string. -- Barry Margolin, barmar@alum.mit.edu Arlington, MA *** PLEASE post questions in newsgroups, not directly to me *** *** PLEASE don't copy me on replies, I'll read them in the group ***