非交互式emacs正则表达式替代

时间:2014-12-01 19:00:06

标签: regex emacs elisp

emacs lisp中是否有(非交互式)函数替换任意字符串中匹配的正则表达式?

(sub regex search-string replace-string)

,如

(sub "[^.x/]" "beef./xxfoo" "")
;; => "./xx"

1 个答案:

答案 0 :(得分:2)

是的,请参阅功能replace-regexp-in-string。就这么简单。

要替换缓冲区中的匹配文本,您需要replace-regexp

替换不需要是文字字符串,但可以涉及检索正则表达式匹配和其他操作的部分。使用C-h f查看这些功能的文档。