Community
    • Login

    Need help with Replacing lines

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    2 Posts 2 Posters 442 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.
    • WTFerwarwaW
      WTFerwarwa
      last edited by

      I have about 100k lines like these
      LoydNova47:TEHHA3HFW35GG:cc9sttdcb6tkb8z31hs7i3p3sss8rx:hongjgd45td5wnumnpe4gzwn3iiiglsq09d0vptyll9mrc7p9d
      PierreIncendi5fary7:UNM7EAG4QBPHGY:vr2534igqrj1llisopis4l1yc1z4py:6p22mq1ruxfr8i3nz0cihl2bby6j944r4hcz602w9x99neftrd
      KlinklangHJunior7:EFTEXFGP5DWKBD:n6hbd3869c0h48kzg8r89rejg344qb:r8hq5i2yoladarotzkhlhe82kucirqmn26t9mne7jwjbuwiy3w
      And i want to change each line to only this
      LoydNova47:TEHHA3HFW35GG
      PierreIncendi5fary7:UNM7EAG4QBPHGY
      KlinklangHJunior7:EFTEXFGP5DWKBD
      can someone help me how to do that?

      1 Reply Last reply Reply Quote 0
      • guy038G
        guy038
        last edited by guy038

        Hello @ilya-levadny and All,

        Actually, you want to delete all characters located after the second colon character, included, of any line

        Indeed, not difficult with regular expressions !

        • Open the Replace dialog ( Ctrl + H )

        • SEARCH (?-s)^(.+?:.+?):.+

        • REPLACE \1

        • Select the Regular expression search mode

        • Check, preferably, the Wrap around option

        • Click, once on the Replace All button or several times on the Replace button


        An other formulation would be :

        • SEACRH (?-s)^.+?:.+?\K:.+

        • REPLACE Leave EMPTY

        This time, due to the \K syntax you must use the Replace All button, exclusively


        Notes :

        • The (?-s) in-line modifier means that dot ( . ) matches any single standard character, only

        • The .+?: part looks for the shortest non-null range of characters till a colon ( : )

        • The part between parentheses ( .+?:.+? ) is stored as group 1, which must be rewritten, during the replacement phase

        • At the end, the .+ syntax represents the rest of the line, after the second colon char, included, of the current line

        • In the second version, after matching the implicit group 1, the \K syntax resets the regex engine, so the final overall match is the part :.+ which corresponds to the second colon char with all the subsequent chars of current line, which are deleted as the replacement zone is empty

        Best Regards,

        guy038

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