unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* regexp-quote for replacements
@ 2004-09-12 18:13 Roland Winkler
  2004-09-13 16:17 ` Stefan Monnier
  0 siblings, 1 reply; 2+ messages in thread
From: Roland Winkler @ 2004-09-12 18:13 UTC (permalink / raw)



I want to construct replacement patterns automatically.
Does the following piece of code insert the value of bar in the
replacement, no matter what the string bar is?
The point is that I want the optional arg LITERAL of replace-match
to be nil.

(let* ((foo "foo")
       ;; this string should appear in the replacement
       (bar "bar.\\")
       ;; the following is like regexp-quote for replacements?
       (baz (replace-regexp-in-string "\\\\" "\\\\" bar nil t)))
  (string-match "\\(foo\\)" foo)
  (replace-match (concat "\\1 " baz " \\1") nil nil foo))


Thanks a lot,

Roland

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

* Re: regexp-quote for replacements
  2004-09-12 18:13 regexp-quote for replacements Roland Winkler
@ 2004-09-13 16:17 ` Stefan Monnier
  0 siblings, 0 replies; 2+ messages in thread
From: Stefan Monnier @ 2004-09-13 16:17 UTC (permalink / raw)


> I want to construct replacement patterns automatically.
> Does the following piece of code insert the value of bar in the
> replacement, no matter what the string bar is?
> The point is that I want the optional arg LITERAL of replace-match
> to be nil.

>        ;; the following is like regexp-quote for replacements?
>        (baz (replace-regexp-in-string "\\\\" "\\\\" bar nil t)))

Yes, this will do a "quote" w.r.t the `literal' argument of
replace-match.  But it won't protect from case-fiddling.  For that I think
the only solution is the `fixedcase' argument (i.e. global to the
whole replacement text).


        Stefan

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

end of thread, other threads:[~2004-09-13 16:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-09-12 18:13 regexp-quote for replacements Roland Winkler
2004-09-13 16:17 ` Stefan Monnier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).