【问题标题】:Substitute one group with another group用另一组替换一组
【发布时间】:2021-12-23 13:38:25
【问题描述】:
<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"/>

我想将 P3(x) 的值放入 P2(x)。

到目前为止,我有一个可行的解决方案,但这不是最漂亮的;

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

它迫使我使用 P2 x="\4 替代而不是简单的 \4

https://regex101.com/r/iua3p0/1

我正在尝试将第 2 组与第 1 组分开,将第 4 组与第 3 组分开, 同时允许我在第 2 组中使用第 4 组的值

【问题讨论】:

    标签: regex notepad++ substitution


    【解决方案1】:

    你可以试试这个正则表达式:

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

    替换:

    \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
    

    proof

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-05
      • 2014-09-05
      • 1970-01-01
      • 2013-07-11
      • 1970-01-01
      • 2013-10-05
      • 2017-05-11
      • 2011-04-19
      相关资源
      最近更新 更多