regex - 非交互式 emacs 正则表达式替代品

标签 regex emacs elisp

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

(sub regex search-string replace-string)

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

最佳答案

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

要替换缓冲区中的匹配文本,您可以使用 replace-regexp

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

关于regex - 非交互式 emacs 正则表达式替代品,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27235293/

相关文章:

javascript - 基于正则表达式用新的 DOM 节点替换 TextNode 中的文本

python - 正则表达式在Python中识别医疗受益人标识符(MBI)

emacs - 如何更改具有 lambda :set function without customize? 的 defcustom 变量

list - 为什么对带有 elisp 的列表进行更改?

Emacs 自动完成 : the function `define-package` is not known

Python re.findall() 没有按预期工作

regex - sed -E 和 sed -e 有什么区别

emacs - 删除截断线末端的字形

emacs - 我可以流浪汉中的文件吗?

algorithm - (emacs) 口齿不清 : search anything in a ((nested) list)