Notepad++ RegEx Find/Replace 指定组和反向引用

Notepad++ RegEx Find/Replace specified group and backreference

我在让我的 RegEx find/replace 在 NPP 中工作几个小时时遇到了一些麻烦。这是我正在处理的文件中的一些代码: https://regex101.com/r/kQdy4L/6/ 我的目标是用他们的 id name

替换所有的“0>.|.|...”

测试字符串

<movingPart index="0>8|1|3" referencePoint="0>8|1|0|4" referenceFrame="0>" scaleZ="true"/>
bla
bla
<i3dMapping id="KroneComprimaV180XC" node="0>" />
<i3dMapping id="novoGripPart2_fixPoint" node="0>8|1|0|4" />
<i3dMapping id="novoGrip_part2" node="0>8|1|3" />

替换

<movingPart index="novoGrip_part2" referencePoint="novoGripPart2_fixPoint" referenceFrame="KroneComprimaV180XC" scaleZ="true"/>
bla
bla
<i3dMapping id="KroneComprimaV180XC" node="0>" />
<i3dMapping id="novoGripPart2_fixPoint" node="0>8|1|0|4" />
<i3dMapping id="novoGrip_part2" node="0>8|1|3" />

经过一些 tial´n´error 我得到了这个正则表达式

(".[>].*?")|<i3dMapping id=(?P<name>".*?") node=(".[>].*?")
(".[>].*?")|<i3dMapping id=(?P<name>".*?") node=(".[>].*?")\=1

它确实找到了节点+id 或仅找到我需要替换的节点,但是我不知道如何替换所有“0>.|.|”。 id 名称

感谢您帮助我,这是我第一次遇到正则表达式,所以这让我很困惑。 干杯弗雷德

您可以使用此正则表达式为您进行替换:

(?<=(index|Point|Frame)=")([^"]+)(?=".*?id="([^"]+)" node="")

它对 index="Point="Frame=" 中的一个使用正向后视(请注意,我们必须切断 reference,因为后视必须是固定的长度),后跟一些非 " 字符(该值在第 2 组中捕获),然后是一个看起来像 id="someidvalue" node="" 的字符串的正面前瞻,其中 </code> 指的是之前捕获的值。值 <code>someidvalue 在第 3 组中捕获。

然后您可以替换为 </code>。请注意,您需要使用 <code>Replace All,出于某种原因,Notepad++ 不喜欢逐场替换它。

这是 regex101.com

上的正则表达式演示