[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Question about string-match and match-string

From: Suvayu Ali
Subject: Question about string-match and match-string
Date: Wed, 17 Jul 2013 10:17:04 +0200
User-agent: Mutt/1.5.21 (2012-12-30)


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)
  call-interactively(eval-last-sexp nil nil)

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.


Open source is the future. It sets us free.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]