在elisp中(伪)调用正则的交互式特性

感觉上也可以直接从 query-replace 里拼凑出来?

(defun my/replace-regexp (regexp replacement)
  "`replace-regexp', non-interactively."
  (perform-replace
   regexp
   (query-replace-compile-replacement replacement t)
   nil t nil))

运行:

(with-temp-buffer
  (insert "hello world
foo123
bar456")
  (goto-char (point-min))
  (my/replace-regexp "[a-z]+" "\\,(upcase \\&)")
  (buffer-string))

结果:

"HELLO WORLD
FOO123
BAR456"
1 个赞