Community
    • Login

    Macro for Open, Find and Replace and Save

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    22 Posts 6 Posters 4.5k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • José Luis Montero CastellanosJ
      José Luis Montero Castellanos @Lycan Thrope
      last edited by

      @Lycan-Thrope :
      I will take your comments into account.
      Greetings :-)

      1 Reply Last reply Reply Quote 1
      • Jaguar AsadJ
        Jaguar Asad @guy038
        last edited by PeterJones

        @guy038 said in Macro for Open, Find and Replace and Save:

        Hello, @josé-luis-montero-castellanos, @aln-kilborn and all,

        @josé-luis-montero-castellanos, regarding your regex S/R :

        • SEARCH (?s)(<St)(.)(/S)(.)(<Xt)(.)(/X)|(<Xt)(.)(/X)(.)(<St)(.)(/S)

        • REPLACE ?1\5\2\7\4\1\6\3:${12}${9}${14}${11}${8}${13}${10}

        Why do you need the leading in-line modifier (?s), in the search part ? Do you mean that the single char . in group 2, 4, 6, 9, 11 and 13 may also represent a line-break char ( \r or \n ) ?

        I suppose not ! Then, your correct search regex is rather :

        (?-s)(<St)(.)(/S)(.)(<Xt)(.)(/X)|(<Xt)(.)(/X)(.)(<St)(.)(/S)

        where any . single char will represent a non-break char, only !


        Now, I noticed that the groups used, in replacement, for each alternative of the search regex, are in the same order ! Then, you can use, preferably, a specific feature of the Boost Regex engine, called Branch Reset

        For instance, in your regex, the numbers of each group are :

        (?-s)(<St)(.)(/S)(.)(<Xt)(.)(/X)|(<Xt)(.)(/X)(.)(<St)(.)(/S)
        Gr : 1    2  3   4  5    6  7   |8    9  10  11 12   13 14  
        

        If we use the Branch Reset feature the search regex becomes :

        (?-s)(?|(<St)(.)(/S)(.)(<Xt)(.)(/X)|(<Xt)(.)(/X)(.)(<St)(.)(/S))
        Gr:     1    2  3   4  5    6  7   |1    2  3   4  5    6  7
        

        Thus, your entire regex S/R can be simplified as below :

        • SEARCH (?-s)(?|(<St)(.)(/S)(.)(<Xt)(.)(/X)|(<Xt)(.)(/X)(.)(<St)(.)(/S))

        • REPLACE \5\2\7\4\1\6\3


        For instance, given this INPUT text :

        <St2/S4<Xt6/X
        <Xt9/XB<StD/S
        

        You would get the OUTPUT text, below :

        <Xt2/X4<St6/S
        <St9/SB<XtD/X
        

        Notes :

        • The Regular expression option must be selected

        • Preferably, tick the [Wrap around](https://www.ahijoy.com/) option

        Best Regards,

        guy038

        I tried it but didn’t work

        1 Reply Last reply Reply Quote 0
        • First post
          Last post
        The Community of users of the Notepad++ text editor.
        Powered by NodeBB | Contributors