• Login
Community
  • Login

Remove unwanted CRLF in paragraphs

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
4 Posts 3 Posters 3.8k 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.
  • J
    Jeroen Borgman
    last edited by Jeroen Borgman Oct 23, 2019, 9:00 AM Oct 23, 2019, 8:59 AM

    I want to change:

    Just some text<CRLF>
    I wrote to<CRLF>
    serve as example.<CRLF>
    <CRLF>
    

    into:

    Just some text I wrote to serve as example.<CRLF>
    <CRLF>
    

    In some 200 files, each files containing lots of these paragraphs.
    How can this be done?

    E 1 Reply Last reply Oct 23, 2019, 11:30 AM Reply Quote 0
    • E
      Ekopalypse @Jeroen Borgman
      last edited by Oct 23, 2019, 11:30 AM

      @Jeroen-Borgman

      How can this be done?

      By finding a pattern which all have in common.
      Without such a pattern, … by manually joining the lines.

      1 Reply Last reply Reply Quote 1
      • G
        guy038
        last edited by Oct 23, 2019, 11:35 AM

        Hello, @jeroen-borgman, and All,

        Not difficult with regexes. Indeed !

        However I advice you to get rid of any trailing space characters, first ! Two possibilities :

        • Use the N++ option Edit > Blank Operations > Trim Trailing Space

        • Execute the regex S/R :

          • SEARCH \h+$

          • REPLACE Leave EMPTY


        Now, given, for instance, the sample text, below, without any trailing space :

        Just some text
        I wrote to<
        serve as example
        
        Just some text
        I wrote to<
        serve as example
        
        
        A single line !
        
        
        
        A last
        paragraph to
        see if the
        result is
        OK
        
        

        Then, the regex S/R :

        • SEARCH (?-s).\K\R(?!\R)

        • REPLACE \x20

        with a click on the Replace All button, would return the text :

        Just some text I wrote to< serve as example
        
        Just some text I wrote to< serve as example
        
        
        A single line !
        
        
        
        A last paragraph to see if the result is OK
        
        

        Notes :

        • First, the part (?-s) means that any dot (. ) will represents a single standard character, only and not EOL ones

        • Then the part .\K\R looks for any standard char, right before an end of line and, due to the \K syntax, the regex engine considers the regex at the right of \K, i.e. the syntax \R which represents any form of EOL ( \r\n if Windows, \n if Unix or \r if Mac )

        • Finally, the (?!\R) part is a negative look-around, i.e. a condition which must be verified. This condition force the replaceent of the EOL character(s) of a line ONLY IF it is not followed, itself, with other EOL character(s)

        • In replacement, the \x20 syntax is a synonym of the space character

        Best Regards,

        guy038

        J 1 Reply Last reply Oct 23, 2019, 11:59 AM Reply Quote 2
        • J
          Jeroen Borgman @guy038
          last edited by Oct 23, 2019, 11:59 AM

          @guy038 Thanks for this, works like a charm!
          I will study the search syntax with the REGEX doc on the side to do this myself next time.

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