Search code examples
regexnotepad++

Regex to Locate Carriage Return Line Feed Followed by anything except an 8 digit number and a |


All.

I have some data with some improper line breaks. I would like to search and replace any CR LF that is not followed by an 8 digit number and a pipe.

For example:

12345678|Text|Text CRLF
123.4567|Text|Text CRLF  
Text|4567890|Text

This text above should change to:

12345678|Text|Text 123.4567|Text|Text Text|4567890|Text

I have tried the following:

\r\n([^[0-9]{8}\|])

Any help is very appreciated.


Solution

    • Ctrl+H
    • Find what: \R(?!\d{8}\|)
    • Replace with: LEAVE EMPTY
    • CHECK Wrap around
    • CHECK Regular expression
    • Replace all

    Explanation:

    \R              # any kind of linebreak, you can use \r\n if you want to replace ONLY \r\n
    (?!             # negative lookahead, make we haven't after:
        \d{8}           # 8 digit
        \|              # a pipe
    )               # endd lookahead
    

    Screenshot (before):

    enter image description here

    Screenshot (after):

    enter image description here