Home > database >  Substitute one group with another group
Substitute one group with another group

Time:11-12

<P1 x="-0,36935" y="0,26315"/><P2 x="4,29731" y="0,26315"/><P3 x="5,29731" y="-0,40351"/><P4 x="-0,36935" y="-0,40351"/>
<P1 x="4,64065" y="0,26315"/><P2 x="5,97398" y="0,26315"/><P3 x="5,30731" y="-0,40351"/><P4 x="4,64065" y="-0,40351"/>

I want to put a value of P3(x) into P2(x).

So far I have a somewhat working solution, that is not the prettiest;

((?:P2 x=\")(.*?[^\"] )(?=. ((?:P3 x=\")(.*?[^\"] ))))

It forces me to use P2 x="\4 substitution instead of simply \4

Group Substitution

CodePudding user response:

You may try this regex:

(?<=<P2 x=")[\d,-] (?=.*<P3 x="([\d,-] )")

Substitution:

\1
(?<=<P2 x=")           // positive lookbehind, the following rule must be preceded by <P2 x="
[\d,-]                 // a set of characters formed by digits, comma and -
(?=.*<P3 x="([\d,-] )) // positive lookahead, find the x value of P3 and store it in group 1

See the proof

  • Related