非交互式Emacs正则表达式替代 [英] Non-interactive emacs regex substitute
本文介绍了非交互式Emacs正则表达式替代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
emacs lisp中是否有一个(非交互式)函数来替换任意字符串中匹配的正则表达式?
Is there a (non-interactive) function in emacs lisp that replaces a matched regex in an arbitrary string?
ie
(sub regex search-string replace-string)
如
(sub "[^.x/]" "beef./xxfoo" "")
;; => "./xx"
推荐答案
是,请参见函数替换字符串中的正则表达式
。如此简单。
Yes, see function replace-regexp-in-string
. Simple as that.
要替换缓冲区中的匹配文本,您可以使用 replace-regexp
。
And to replace matching text in a buffer, you have replace-regexp
.
替换不必是文字字符串,但是可以涉及检索部分regexp匹配和其他操作。使用 C-h f
查看这些功能的文档。
The replacement does not need to be a literal string, but can involve retrieving parts of the regexp match and other manipulations. Use C-h f
to see the doc for these functions.
这篇关于非交互式Emacs正则表达式替代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文