英文:
Notepad++ find value with regex and replace to value that find with another regex
问题
You can replace the value between <id1>
and <id1>
with the value from <id2>
using Notepad++ and regular expressions. Here's a possible regex pattern to find and replace:
Find what:
<id1>(.*?)<\/id1>.*?<id2>(.*?)<\/id2>
Replace with:
<id1><\/id1>
This regex pattern captures the values between <id1>
and <id2>
and replaces the content between <id1>
with the content between <id2>
.
英文:
i have a string:
...some values...<id1>10052023</id1>...some others...<id2>306689461795</id2>...
i need to replace value between id1 with value from id2, is it possible to do with npp?
i know about groups but i don't know how to use it properly in this case.
my value can be found and stored in group 1 with regex like this:
^.*<id1>(.*)</id1>.*$
am i right?
答案1
得分: 0
Here is the translated content:
使用 xmlstarlet
(适用于所有平台):
$ cat file
<root>
...一些值...<id1>10052023</id1>...其他一些值...<id2>306689461795</id2>...
</root>
<p>
$ xmlstarlet edit -d '//id1/text()' -u '//id1' -x '//id2/text()' file
<?xml version="1.0"?>
<root>
...一些值...<id1>306689461795</id1>...其他一些值...<id2>306689461795</id2>...
</root>
请注意,我已将XML代码部分保持不变。
英文:
With xmlstarlet
(available on all platforms):
$ cat file
<root>
...some values...<id1>10052023</id1>...some others...<id2>306689461795</id2>...
</root>
<p>
$ xmlstarlet edit -d '//id1/text()' -u '//id1' -x '//id2/text()' file
<?xml version="1.0"?>
<root>
...some values...<id1>306689461795</id1>...some others...<id2>306689461795</id2>...
</root>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论