all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Question about string-match and match-string
@ 2013-07-17  8:17 Suvayu Ali
  2013-07-17  8:35 ` Suvayu Ali
  2013-07-17  8:53 ` Nicolas Richard
  0 siblings, 2 replies; 12+ messages in thread
From: Suvayu Ali @ 2013-07-17  8:17 UTC (permalink / raw)
  To: Emacs help

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.



^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2013-07-21  8:15 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-17  8:17 Question about string-match and match-string Suvayu Ali
2013-07-17  8:35 ` Suvayu Ali
2013-07-17  8:44   ` Rasmus
2013-07-17  8:55     ` Suvayu Ali
2013-07-18  8:00     ` Julien Cubizolles
2013-07-18  8:33       ` Rasmus
2013-07-20 15:26         ` Julien Cubizolles
2013-07-20 22:25           ` Rasmus
2013-07-21  0:41             ` Rasmus
2013-07-21  8:15               ` Julien Cubizolles
2013-07-17  8:53 ` Nicolas Richard
2013-07-17 10:02   ` Suvayu Ali

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.