繁体   English   中英

Emacs XML模式:在文本中搜索并替换(不是标记)

[英]Emacs XML mode: search-and-replace in text (not markup)

Emacs中是否有一种简单的方法来搜索和替换XML文件中的文本,但是使s&r操作仅作用于文档文本而不是标记?

例如:

...
There is some text above here
[mark-starts-here]
<some_tag key="value">
  text
</some_tag>
[mark-ends-here]
There is some text below here
...

E替换e得到:

...
There is some text above here
[mark-starts-here]
<some_tag key="value">
  tExt
</some_tag>
[mark-ends-here]
There is some text below here
...

我不知道xml模式是否具有类似的内置功能,但这是一个简单的功能:

(defun my-replace-outside-of-tags (regexp replacement)
  (while (re-search-forward regexp nil t)
    (unless (save-match-data
              (looking-at "[^<>]*>"))
      (replace-match replacement))))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM