Shaun Badertscher
Shaun Badertscher

Reputation: 21

Removing line breaks NOT preceded by NULL

I've got a string of data that have random CRLF inserted in the lines which I need to remove and proper CRLF ending the data which I need to keep.

I've tried using Notepad++ regex trying to replace the following with empty: [^NULL]\r\n

However, it does not remove the inserted CRLFs. Any thoughts on how best to use this in Notepad++?

Inserted CRLF

Proper ending CRLF

Upvotes: 1

Views: 487

Answers (2)

Toto
Toto

Reputation: 91518

This will replace every linebreak that is not preceeded by "NULL".


  • Ctrl+H
  • Find what: (?<!NULL)\R
  • Replace with: # a space OR any thing you want that will replace the linebreak
  • CHECK Wrap around
  • CHECK Regular expression
  • Replace all

Explanation:

(?<!            # negative lookbehind, make sure we haven't before:
    NULL            # literally NULL
)               # end lookbehind
\R              # any kind of linebreak (i.e. \r or \n or \r\n)

Screenshot (before):

enter image description here

Screenshot (after):

enter image description here

Upvotes: 1

Matthew
Matthew

Reputation: 25793

Not sure if this is exactly what you mean, but you can use the Extended search mode to match \r\n specifically.

Find what: NULL\r\n
Replace with:

Replace dialog box

Before: Before replacement

After: After replacement

Upvotes: 0

Related Questions