在Notepad ++中捕获一组数字以将其他位置放在括号中的正则表达式中?

时间:2015-03-12 13:41:47

标签: regex

好的,我有一个像这样的巨大XML:

<imgdir name="5010000">
<string name="name" value="Sunny Day"/>
<string name="desc" value="A special effect in which you&apos;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 &amp; the Stars"/>
<string name="desc" value="A special effect in which you&apos;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&apos;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&apos;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&apos;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 &amp; the Stars (5010001)"/>
<string name="desc" value="A special effect in which you&apos;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&apos;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&apos;ll see Lilly the cute little devil floating around next to you. Designate a HotKey to turn the effect on/off."/>
</imgdir>

我已经尝试过调查“捕捉群体”,我认为这就是我需要的东西,但我无法弄清楚如何让它们输出到我想要的地方。有什么想法吗?

1 个答案:

答案 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)。