I'd like to define a function to do a query-replace-regexp
with a pattern I often use. When not using capture groups, it works:
(defun my-replace ()
(interactive)
(query-replace-regexp "[[:nonascii:][:ascii:]]*xxx" "replacedText" nil (point-min) (point-max)))
But I couldn't figure out how to use capture groups -- neither '\(\)' nor '()' works:
(defun my-replace ()
(interactive)
(query-replace-regexp "([[:nonascii:][:ascii:]]*)xxx" "\1replacedText" nil (point-min) (point-max)))
(defun my-replace ()
(interactive)
(query-replace-regexp "\([[:nonascii:][:ascii:]]*\)xxx" "\1replacedText" nil (point-min) (point-max)))
But when invoked with M-x query-replace-regexp
, \([[:nonascii:][:ascii:]]*\)xxx
would work.
\1
or\\1
is working as the replacement part. – Meng Lu Jun 24 '15 at 07:41"\\1replacedText"
as the replacement string. – Sean Jun 24 '15 at 07:50\\1
does work. It was a faulty regexp that caused me to think it didn't, – Meng Lu Jun 24 '15 at 17:29