Community
    • Login

    Regex find/replace EOL except if..

    Scheduled Pinned Locked Moved General Discussion
    3 Posts 2 Posters 534 Views 2 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.
    • Mech MonM Offline
      Mech Mon
      last edited by

      Hello all,
      I have a text file that was a save as text doc from word. The main content is a multi level bulleted list. However some of the bullets were wrapped to the next line and these were converted to a \r\n. I am trying to do a search and replace for the EOL that is not followed by a word char, period, and space.
      Example:

      This line was continued to[find this \r\n]
      a new line, but is actually part of the line above.[NOT this \r\n]
      1. but this line should correctly be on a new line.[find this \r\n]
      [empty line]
      A. and this one should as well[find this \r\n]
      however this line should be concatenated onto the previous line.[NOT this \r\n]
      5. New line that references 1. so cannot just remove all and replace.[find this \r\n]
      

      If I use \r\n(?<=\w.\s) the pattern is not found.
      \r\n(?<!\w.\s) finds the new line at the end of each line not matter what the start of the next line is. I have been through every iteration I can think of and have used online regex testers Regex101 and regex storm. All to no avail.
      Any tips?

      Mon

      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP Online
        PeterJones @Mech Mon
        last edited by

        @mech-mon ,

        Thank you for supply the data in a text box, and showing us what you already tried.

        \r\n(?<!\w.\s)

        You were oh so close! You made it a negative lookbehind. You wanted a negative lookahead. And . has special meaning, so you need to escape it to match a literal period character. Hence, use \r\n(?!\w\.\s)

        If I do that as the FIND, and replace with empty, I get

        This line was continued to[find this \r\n]a new line, but is actually part of the line above.[NOT this \r\n]
        1. but this line should correctly be on a new line.[find this \r\n][empty line]
        A. and this one should as well[find this \r\n]however this line should be concatenated onto the previous line.[NOT this \r\n]
        5. New line that references 1. so cannot just remove all and replace.[find this \r\n]
        

        which I believe is what you want.

        Mech MonM 1 Reply Last reply Reply Quote 2
        • Mech MonM Offline
          Mech Mon @PeterJones
          last edited by

          @peterjones thank you yes exactly what I was looking for. I did have the period escaped, but was not clear about the positive/negative look ahead/behind. I didn’t RTFM close enough.

          1 Reply Last reply Reply Quote 0

          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