From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Suvayu Ali Newsgroups: gmane.emacs.help Subject: Question about string-match and match-string Date: Wed, 17 Jul 2013 10:17:04 +0200 Message-ID: <20130717081704.GB16899@kuru.dyndns-at-home.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1374049044 8547 80.91.229.3 (17 Jul 2013 08:17:24 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 17 Jul 2013 08:17:24 +0000 (UTC) To: Emacs help Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Jul 17 10:17:26 2013 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 1UzMvN-0000yt-Rs for geh-help-gnu-emacs@m.gmane.org; Wed, 17 Jul 2013 10:17:25 +0200 Original-Received: from localhost ([::1]:37517 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UzMvN-0007Yr-EU for geh-help-gnu-emacs@m.gmane.org; Wed, 17 Jul 2013 04:17:25 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34632) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UzMvC-0007Xj-PC for help-gnu-emacs@gnu.org; Wed, 17 Jul 2013 04:17:15 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UzMv8-0002tG-6W for help-gnu-emacs@gnu.org; Wed, 17 Jul 2013 04:17:14 -0400 Original-Received: from mail-wi0-x22e.google.com ([2a00:1450:400c:c05::22e]:60571) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UzMv8-0002t5-0S for help-gnu-emacs@gnu.org; Wed, 17 Jul 2013 04:17:10 -0400 Original-Received: by mail-wi0-f174.google.com with SMTP id k10so5076428wiv.1 for ; Wed, 17 Jul 2013 01:17:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:date:from:to:subject:message-id:mime-version:content-type :content-disposition:user-agent; bh=apNoKJvWR1+gx5zUEAuj1kW2QVc3ThsHT3//L9RLRLc=; b=TcSVk07izHyBXHBbGsR9rzNiWAJMX7A7vB4slXrn5K6E72c3LxAXsbE3rOHXcimeEz OtVgTK5mberBCfDXnWl2DwQnzENnUe2PhmFDOQKYuYGMfFrQqwkQ1I+2Gbx8Uz3xJTMq ljsDIyKCmlL4DsPx+j4U25h8nFzDwlXXaHRZf2Kr0NONY+BG3nmgTtNam6wfx2eKt0+m nu7pRV6pk1MaDdLjrQPVK8yft7zdyBwrsa5+2mQDguz5TLkzYmUTYS3TwewL5poUfHlU Odbp5v53KVYS5nwR5RHGAmxuvfmbQY7nSi8/usDwvgvOKWMWJFNpPC6OgXs4pSdFn8Nz QCIA== X-Received: by 10.180.212.70 with SMTP id ni6mr11453747wic.11.1374049029319; Wed, 17 Jul 2013 01:17:09 -0700 (PDT) Original-Received: from kuru.dyndns-at-home.com (sd44012d5.adsl.online.nl. [212.64.18.213]) by mx.google.com with ESMTPSA id r8sm33208883wiz.5.2013.07.17.01.17.07 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 17 Jul 2013 01:17:07 -0700 (PDT) Content-Disposition: inline User-Agent: Mutt/1.5.21 (2012-12-30) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c05::22e 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:92193 Archived-At: Hi, I was writing a filter for Org mode and came across this confusion. I want to parse a string with LaTeX code and delete matching sub-expressions. As a test I tried this: (let ((test "\\section{Heading{ignoreheading}}\nText\n")) (string-match "\\(\\\\\\\\section{.+{ignoreheading}}\\\\n\\)\\(.+\\)" test) (match-substitute-replacement "" t nil test 1) ) But evaluating the above I get the following backtrace. Debugger entered--Lisp error: (args-out-of-range -1 -1) replace-match("" t nil "{" 1) match-substitute-replacement("" t nil "\\section{Heading{ignoreheading}}\nText\n" 1) (let ((test "\\section{Heading{ignoreheading}}\nText\n")) (string-match "\\(\\\\\\\\section{.+{ignoreheading}}\\\\n\\)\\(.+\\)" test) (match-substitute-replacement "" t nil test 1)) eval((let ((test "\\section{Heading{ignoreheading}}\nText\n")) (string-match "\\(\\\\\\\\section{.+{ignoreheading}}\\\\n\\)\\(.+\\)" test) (match-substitute-replacement "" t nil test 1)) nil) eval-last-sexp-1(nil) eval-last-sexp(nil) call-interactively(eval-last-sexp nil nil) command-execute(eval-last-sexp) I do not understand the error at all, since if I insert something like (prin1 test) before the (match-substitute-replacement ..) in my example code, I get the expected output (the value of test as bound by let). Where am I going wrong? Thank you for any guidance. PS: I'm also not very clear why we need 4 \-s in the regex to match a single \ in the string. I came up with it by trial and error with the regexp-builder. Any explanation about that would also be great. -- Suvayu Open source is the future. It sets us free.