Dom*_*ger 49 regex emacs replace
每隔一段时间我就想替换所有值的实例,例如:
<BarFoo>
Run Code Online (Sandbox Code Playgroud)
同
<barfoo>
Run Code Online (Sandbox Code Playgroud)
即,使用小写等效项对尖括号内的所有内容进行正则表达式替换.
任何人都有一个很好的Lisp片段吗?假设我们只处理ASCII值是安全的.任何通用的足以获得完整正则表达式的奖励积分,并不仅仅处理尖括号示例.更多奖励指向刚才使用的答案M-x query-replace-regexp
.
谢谢,
大教堂
Luk*_*vin 78
尝试M-x query-replace-regexp
使用"<\([^>]+\)>"
搜索字符串和"<\,(downcase \1)>"
替换.
这应该适用于Emacs 22及更高版本,请参阅此Steve Yegge博客文章,了解有关如何在替换字符串中使用Lisp表达式的更多详细信息.
对于早期版本的Emacs,您可以尝试这样的事情:
(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))))
Run Code Online (Sandbox Code Playgroud)