Emacs: regular expression replacing to change case

后端 未结 1 1315
攒了一身酷
攒了一身酷 2020-12-23 13:39

Every once in a while I want to replace all instances of values like:


with


相关标签:
1条回答
  • 2020-12-23 14:12

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

    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.

    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))))
    
    0 讨论(0)
提交回复
热议问题