假设我的列表中有 100000 个单词(例如)苹果橙子葡萄香蕉.... 等
我需要这种格式
<command name="FindRep" enabled="True">
<find xml:space="preserve">FRUITS</find>
<replace></replace>
<flags></flags>
</command>
但将水果改为苹果、橙子、葡萄等
<command name="FindRep" enabled="True">
<find xml:space="preserve">Apple</find>
<replace></replace>
<flags></flags>
</command>
<command name="FindRep" enabled="True">
<find xml:space="preserve">Orange</find>
<replace></replace>
<flags></flags>
</command>
<command name="FindRep" enabled="True">
<find xml:space="preserve">Grape</find>
<replace></replace>
<flags></flags>
</command>
答案1
- Ctrl+H
- 找什么:
.+
- 用。。。来代替:
<command name="FindRep" enabled="True">\n <find xml:space="preserve">$0</find>\n <replace></replace>\n <flags></flags>\n</command>
- 查看 环绕
- 查看 正则表达式
- 取消选中
. matches newline
- Replace all
解释:
.+ # 1 or more any character but newline
\S+
替代品:
<command name="FindRep" enabled="True"> # literally
\n # linefeed, you can use \r\n for Windows EOL
<find xml:space="preserve"> # literally
$0 # the whole match (i.e. the fruit name)
</find> # literally
\n # linefeed, you can use \r\n for Windows EOL
<replace></replace> # literally
\n # linefeed, you can use \r\n for Windows EOL
<flags></flags> # literally
\n # linefeed, you can use \r\n for Windows EOL
</command> # literally
截图(之前):
截图(之后):
答案2
您甚至不需要正则表达式,只需将水果之间的空格字符替换为:
</find><replace></replace><flags></flags></command><command name="FindRep" enabled="True"><find xml:space="preserve">
然后手动修复文件的开始和结束。