0

I´ve had some trouble getting my RegEx find/replace working in NPP for hours. Here´s some code out of the files I´m working on: https://regex101.com/r/kQdy4L/6/ My goal is to replace all the "0>.|.|..." by their id name

test string

<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" />

substitution

<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" />

After some tial´n´error I got this RegEx

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

Which do find either nodes+ids or only the nodes I need to replace however I can´t figure out how to replace all "0>.|.|." with the id name

Thanks for helping me out, this is the first time I get confronted with RegEx, so this is all very confusing to me. Cheers Fred

2
  • Can you please add an example of expected input and output? Commented Feb 3, 2019 at 7:13
  • @AryJazz thanks for helping me, the RegExp code posted by Nick does exactly what I was looking for. If you are still interested in input and outup check out his regex101 link Commented Feb 4, 2019 at 0:05

1 Answer 1

1

You can use this regexp to do the replacements for you:

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

It uses a positive lookbehind for one of index=", Point=" or Frame=" (note we have to cut the reference off because a lookbehind must be of fixed length), followed by some number of non-" characters (that value being captured in group 2), then a positive lookahead for a string which looks like id="someidvalue" node="\2" where the \2 refers to the value captured earlier. The value someidvalue is captured in group 3.

You can then replace with $3. Note that you need to use Replace All, for some reason Notepad++ doesn't like replacing this on a match by match basis.

Here's a demo of the regex on regex101.com

Sign up to request clarification or add additional context in comments.

1 Comment

Wow, thank you so much, that is exactly what I was looking for. It turned out there are some more dos and don´ts i needed to consider but thanks to you explanation I was able to modify the code so I can use it for all my files (lookbehind with fixed length, never would have thought about that). Thanks mate,

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.