0
I have an XML file (1000s of records, simplified here), structure (e.g. say):
<LIST>
<ITEM_0>
<NAME>Item Name</NAME>
</ITEM_0>
...
<ITEM_9999>
<NAME>Item Name</NAME>
</ITEM_9999>
</LIST>
I need result:
<LIST>
<ITEM>
<ID>0</ID>
<NAME>Item Name</NAME>
</ITEM>
...
<ITEM>
<ID>9999</ID>
<NAME>Item Name</NAME>
</ITEM>
</LIST>
Using Regex:
Find: \<ITEM_(.*)(>)
Replace: ITEM>\n<ID>\1\</ID>
I get:
<LIST>
<ITEM>
<ID>0</ID>
<NAME>Item Name</NAME>
</ITEM>
<ID>0</ID> <-- This line not wanted
...
<ITEM>
<ID>9999</ID>
<NAME>Item Name</NAME>
</ITEM>
<ID>9999</ID> <-- This line not wanted
</LIST>
It's replacing </ITEM>
as well even though (I think) I'm asking it to only replace <ITEM>
- what am I doing wrong/how to fix? I may be missing something regarding grouping (or 'greedy'?) but not sure what and have looked all over for similar. There's a million ways to cut and dice it with something else, but it just bugs me getting so close but not there with NPP.
Help appreciated- thanks.
Late Edit: Even if I get the 1st replace to work right, just the <ITEM_#>
tag, I'm still left with the </ITEM_#>
closing tag as another search/replace operation. The problem here is the current operation replaces both the <ITEM
and </ITEM
tags...
Why not do a regular replace and replace the
</ITEM_
with something else and then run your regex replacement? – Blerg – 2016-08-01T20:02:47.377Yes, thanks, would work but take 2 replaces, whereas x2 search/replace in 1 regex solution below works OK (but with the Q there still outstanding). – Catch21 – 2016-08-02T21:17:38.570