Notepad++ find value with regex and replace to value that find with another regex

huangapple go评论90阅读模式
英文:

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:

  1. <id1>(.*?)<\/id1>.*?<id2>(.*?)<\/id2>

Replace with:

  1. <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:

  1. ...some values...&lt;id1&gt;10052023&lt;/id1&gt;...some others...&lt;id2&gt;306689461795&lt;/id2&gt;...

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:

  1. ^.*&lt;id1&gt;(.*)&lt;/id1&gt;.*$

am i right?

答案1

得分: 0

Here is the translated content:

使用 xmlstarlet(适用于所有平台):

  1. $ cat file
  2. &lt;root&gt;
  3. ...一些值...&lt;id1&gt;10052023&lt;/id1&gt;...其他一些值...&lt;id2&gt;306689461795&lt;/id2&gt;...
  4. &lt;/root&gt;
  5. &lt;p&gt;
  6. $ xmlstarlet edit -d &#39;//id1/text()&#39; -u &#39;//id1&#39; -x &#39;//id2/text()&#39; file
  7. &lt;?xml version=&quot;1.0&quot;?&gt;
  8. &lt;root&gt;
  9. ...一些值...&lt;id1&gt;306689461795&lt;/id1&gt;...其他一些值...&lt;id2&gt;306689461795&lt;/id2&gt;...
  10. &lt;/root&gt;

请注意,我已将XML代码部分保持不变。

英文:

With xmlstarlet (available on all platforms):

  1. $ cat file
  2. &lt;root&gt;
  3. ...some values...&lt;id1&gt;10052023&lt;/id1&gt;...some others...&lt;id2&gt;306689461795&lt;/id2&gt;...
  4. &lt;/root&gt;

<p>

  1. $ xmlstarlet edit -d &#39;//id1/text()&#39; -u &#39;//id1&#39; -x &#39;//id2/text()&#39; file
  2. &lt;?xml version=&quot;1.0&quot;?&gt;
  3. &lt;root&gt;
  4. ...some values...&lt;id1&gt;306689461795&lt;/id1&gt;...some others...&lt;id2&gt;306689461795&lt;/id2&gt;...
  5. &lt;/root&gt;

huangapple
  • 本文由 发表于 2023年5月6日 22:17:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/76189373.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定