[英]Notepad++ Regex Backreference syntax in Search/Replace - \1 or $1
[英]Notepad++ RegEx Find/Replace specified group and backreference
我的RegEx在NPP中找到/替換了好幾個小時,遇到了一些麻煩。 以下是我正在處理的文件中的一些代碼: https ://regex101.com/r/kQdy4L/6/我的目標是用其ID替換所有的“ 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后,我得到了此RegEx
(".[>].*?")|<i3dMapping id=(?P<name>".*?") node=(".[>].*?")
(".[>].*?")|<i3dMapping id=(?P<name>".*?") node=(".[>].*?")\=1
哪一個確實找到了節點+ id或僅找到我需要替換的節點,但是我不知道如何替換所有的“ 0>。|。|”。 ID名稱
感謝您的幫助,這是我第一次遇到RegEx,所以這一切都讓我感到困惑。 干杯弗雷德
您可以使用此正則表達式為您進行替換:
(?<=(index|Point|Frame)=")([^"]+)(?=".*?id="([^"]+)" node="\2")
它對index="
, Point="
或Frame="
之一使用正向后視(注意,我們必須切斷reference
,因為后視必須具有固定的長度),后跟一些非"
字符(該值(在第2組中捕獲),然后對一個看起來像id="someidvalue" node="\\2"
的字符串進行正向查找,其中\\2
表示較早捕獲的值。 值someidvalue
在組3中捕獲。
然后,您可以替換為$3
。 請注意,由於某些原因,Notepad ++不喜歡逐個Replace All
,因此您需要使用“ Replace All
替換”。
這是regex101.com上正則表達式的演示
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.