且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Emacs:正则表达式替换为更改大小写

更新时间:2023-02-15 17:59:31

尝试 Mx query-replace-正则表达式< \([^>] + \)>作为搜索字符串和< \,(downcase \1)>作为替换。

Try M-x query-replace-regexp with "<\([^>]+\)>" as the search string and "<\,(downcase \1)>" as the replacement.

这应该适用于Emacs 22及更高版本,请参阅此 Steve Yegge博客文章有关如何在替换字符串中使用Lisp表达式的更多详细信息。

This should work for Emacs 22 and later, see this Steve Yegge blog post for more details on how Lisp expressions can be used in the replacement string.

对于早期版本的Emacs,您可以尝试以下方式:

For earlier versions of Emacs you could try something like this:

(defun tags-to-lower-case ()
  (interactive)
  (save-excursion
    (goto-char (point-min))
    (while (re-search-forward "<[^>]+>" nil t)
      (replace-match (downcase (match-string 0)) t))))