Community
    • Login

    Regex: Rename Duplicate lines with <!— comments -->

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    3 Posts 2 Posters 263 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.
    • Robin CruiseR
      Robin Cruise
      last edited by Robin Cruise

      hello. I faced a problem, I found the solution, maybe someone needs it.

      If I have more lines with the same content, such as, and I want to rename each one, starting with the last instances:

      <!— comments -->
      ...
      <!— comments -->
      
      bla blah
      
      <!— comments -->
      ...
      <!— comments -->
      

      My solution is this:

      FIND: (?-s)(?:.*\R)*?\K.*(<\!— comments -->).*(?s)(\R.*)\1

      REPLACE BY: \1\2 <!— comments_NEW -->

      after find and replace, (twice, three times, 4 time…) will become:

      <!— comments -->
      ...
      <!— comments -->
      
      <!— comments_NEW -->
      ...
      <!— comments_NEW -->
      

      so on…

      Alan KilbornA 1 Reply Last reply Reply Quote 0
      • Alan KilbornA
        Alan Kilborn @Robin Cruise
        last edited by

        @Robin-Cruise

        In general I’m not sure how useful this is, because the stated goal was to eliminate duplicated lines by renaming them, you’ve still got duplicated lines in the result you show, but now you have TWO sets of duplicates instead of just one. If this is useful for you, then Great!, but I don’t see the utility of this as a general technique where “someone needs it”.

        But I wouldn’t have written to say only that.

        I also wanted to point out that your regular expression is in danger of overflowing the engine if the duplicated lines are too far apart in a large file.

        1 Reply Last reply Reply Quote 0
        • Robin CruiseR
          Robin Cruise
          last edited by

          In my case, I wanted to exchange something between the comments, and I have more comments. So, to do that I had to rename the comments so as not to change everything, and only certain comments.

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