all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#12622: replace-regexp-in-string
@ 2012-10-11 14:17 Andreas Röhler
  2012-10-11 14:44 ` Andreas Schwab
  0 siblings, 1 reply; 9+ messages in thread
From: Andreas Röhler @ 2012-10-11 14:17 UTC (permalink / raw)
  To: 12622

Hi,

the following question was raised at:

http://stackoverflow.com/questions/12809610/replace-regexp-in-string-with-lookahead-behind

I'd like to replace all occurrences of \w \w with \w\\\w in a string, where the \w parts stay the same before and after the replacement, e.g.

[.A foobar] [.B baz]

should result in

[.A\\foobar] [.B\\baz]

;;;;;;;;;;

this might be solved in buffer

by

(while  (re-search-forward "\\_<\\w+\\_>" nil t 1)
   (replace-match (concat "\\\\\\\\" (match-string-no-properties 0) )))

Also would expect a respective form working with replace-regexp-in-string

(setq mystring "[.A foobar] [.B baz]")
(replace-regexp-in-string  "\\_<\\w+\\_>" (concat "\\\\" (match-string-no-properties 0) )   mystring)

but it fails.

When commenting "(match-string 0 str)" as follows it subr.el it works

	(setq matches
	      (cons (replace-match (if (stringp rep)
				       rep
				     (funcall rep
                                               ;; (match-string 0 str)
))
				   fixedcase literal str subexp)

Which has some plausibility: when receiving a user-specified function, there must not be that argument.

Maybe have a look,

Best,

Andreas








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

end of thread, other threads:[~2012-10-12 18:12 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-11 14:17 bug#12622: replace-regexp-in-string Andreas Röhler
2012-10-11 14:44 ` Andreas Schwab
2012-10-11 16:38   ` Andreas Röhler
2012-10-11 16:52     ` Andreas Schwab
2012-10-12  6:32       ` Andreas Röhler
2012-10-12  8:14         ` Andreas Schwab
2012-10-12 14:22         ` Stefan Monnier
2012-10-12 16:07           ` Andreas Röhler
2012-10-12 18:12             ` Stefan Monnier

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.