好的,我有一个像这样的巨大XML:
<imgdir name="5010000">
<string name="name" value="Sunny Day"/>
<string name="desc" value="A special effect in which you'll see a brightly smiling sun floating over you. On the KeyConfig, configure this on a button of your choice to turn the effect on/off."/>
</imgdir>
<imgdir name="5010001">
<string name="name" value="Moon & the Stars"/>
<string name="desc" value="A special effect in which you'll see a brightly smiling moon floating around in a sea of stars over you. On the KeyConfig, configure this on a button of your choice to turn the effect on/off."/>
</imgdir>
<imgdir name="5010002">
<string name="name" value="Colorful Rainbow"/>
<string name="desc" value="A special effect in which you'll see a rainbow in its full 7 colors floating next to you. Designate a HotKey to turn the effect on/off."/>
</imgdir>
<imgdir name="5010003">
<string name="name" value="Little Devil"/>
<string name="desc" value="A special effect in which you'll see Lilly the cute little devil floating around next to you. Designate a HotKey to turn the effect on/off."/>
</imgdir>
我希望获取“imgdir name”的每个值,并将其添加到括号中“string name =”name“”的末尾,如下所示:
<imgdir name="5010000">
<string name="name" value="Sunny Day (5010000)"/>
<string name="desc" value="A special effect in which you'll see a brightly smiling sun floating over you. On the KeyConfig, configure this on a button of your choice to turn the effect on/off."/>
</imgdir>
<imgdir name="5010001">
<string name="name" value="Moon & the Stars (5010001)"/>
<string name="desc" value="A special effect in which you'll see a brightly smiling moon floating around in a sea of stars over you. On the KeyConfig, configure this on a button of your choice to turn the effect on/off."/>
</imgdir>
<imgdir name="5010002">
<string name="name" value="Colorful Rainbow (5010002)"/>
<string name="desc" value="A special effect in which you'll see a rainbow in its full 7 colors floating next to you. Designate a HotKey to turn the effect on/off."/>
</imgdir>
<imgdir name="5010003">
<string name="name" value="Little Devil (5010003)"/>
<string name="desc" value="A special effect in which you'll see Lilly the cute little devil floating around next to you. Designate a HotKey to turn the effect on/off."/>
</imgdir>
我已经尝试过调查“捕捉群体”,我认为这就是我需要的东西,但我无法弄清楚如何让它们输出到我想要的地方。有什么想法吗?
答案 0 :(得分:0)
使用此作为查找:
<imgdir name="(\d+)">(\s+)<string name="name" value="(.*?)"
这是替换:
<imgdir name="$1">$2<string name="name" value="$3 \($1\)"
这会捕获imgdir
名称属性中的数字和string
值属性的值。然后,在替换中使用捕获的组($1
,$2
和$3
)将所需值重新放入。$2
匹配空格或换行符,以确保它们在开始时保持相同的格式(\r\n
或\n
)。