• Login
Community
  • Login

Regex find/replace EOL except if..

Scheduled Pinned Locked Moved General Discussion
3 Posts 2 Posters 274 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.
  • M
    Mech Mon
    last edited by Apr 15, 2022, 2:22 PM

    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

    P 1 Reply Last reply Apr 15, 2022, 2:37 PM Reply Quote 0
    • P
      PeterJones @Mech Mon
      last edited by Apr 15, 2022, 2:37 PM

      @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.

      M 1 Reply Last reply Apr 15, 2022, 3:16 PM Reply Quote 2
      • M
        Mech Mon @PeterJones
        last edited by Apr 15, 2022, 3:16 PM

        @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
        1 out of 3
        • First post
          1/3
          Last post
        The Community of users of the Notepad++ text editor.
        Powered by NodeBB | Contributors