【问题标题】:Find and replace in Notepad++ with specific text在记事本++中查找并替换为特定文本
【发布时间】:2021-01-23 03:41:27
【问题描述】:

我有一个 xml 文件,我需要在其中对元素进行一些更改。

<someElement name="Sometext">

我想用这样的属性修改上面的内容

<someElement name="Sometext" newattribute="Sometext_8c54">

在上面我只想复制 name 属性并创建一个 newattribute ,它的值是 name 属性与 _4digit随机十六进制

如何在记事本++中实现这一点

【问题讨论】:

  • 这与 Python 有什么关系?
  • 我在网上阅读,并认为使用 python 可能是可能的。但由于我是新手,不知道如何实现这一目标
  • 您需要一个支持可编写脚本的宏的文本编辑器,例如EmEditor。如果EmEditor 可以,我可以回答这个问题。
  • 是的,请这样做。它会增加知识。

标签: python hex notepad++


【解决方案1】:

如果你使用EmEditor,按Ctrl + H弹出替换对话框,输入:

查找&lt;(.*?)name="(.*?)"&gt;

替换为\J "&lt;\1name=\"\2\" newattribute=\"\2_" + (Math.floor(Math.random()*16)).toString(16) + (Math.floor(Math.random()*16)).toString(16) + (Math.floor(Math.random()*16)).toString(16) + (Math.floor(Math.random()*16)).toString(16) + "\"&gt;"

设置正则表达式选项,然后点击全部替换

说明

\J 开头的 替换为 字符串表示它是 JavaScript。 \1\2 是指向匹配字符串中的第一个 (.*?) 和第二个 (.*?) 的反向引用。 (Math.floor(Math.random()*16)).toString(16) 是一个随机的十六进制字符。

参考:http://www.emeditor.org/en/howto_search_replacement_expression_syntax.html

【讨论】:

  • 您能否将emeditor 标签添加到您的问题中?谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-08-20
  • 2012-12-10
  • 2013-11-23
  • 2013-05-03
  • 2013-01-03
  • 2017-08-09
  • 1970-01-01
相关资源
最近更新 更多