Community
    • Login

    Remove unwanted CRLF in paragraphs

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    4 Posts 3 Posters 4.6k Views 1 Watching
    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.
    • Jeroen BorgmanJ Offline
      Jeroen Borgman
      last edited by Jeroen Borgman

      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?

      EkopalypseE 1 Reply Last reply Reply Quote 0
      • EkopalypseE Offline
        Ekopalypse @Jeroen Borgman
        last edited by

        @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
        • guy038G Offline
          guy038
          last edited by

          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

          Jeroen BorgmanJ 1 Reply Last reply Reply Quote 2
          • Jeroen BorgmanJ Offline
            Jeroen Borgman @guy038
            last edited by

            @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

            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

            With your input, this post could be even better 💗

            Register Login
            • First post
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors