Search code examples
regexreplacenotepad++regular-languageinverse

Partial replacement for a searched regex in notepad++ while search criteria contains not match condition


I am trying to do a find and replace on notepad++ for data shaped as below, unfortunately for now I am not successful.

My data look like this (keeping in mind this is a huge CSV):

1223752, filed1Row1, filed2Row1, filed3
100% Row1
1223698 filed1Row2, filed2Row2, filed3
200$ Row3

Expected output

1223752, filed1Row1, filed2Row1, filed3 100% Row1
1223698 filed1Row2, filed2Row2, filed3 200$ Row3

I am trying to remove the new line making the first row complete.

This is the search I am doing:

\n(\d)(\d)(\d)[^(\d)]
replacing this with
$1$2$3

However this is removing the non digit characters ($%) I want to keep these and only remove the new line.


Solution

    • Ctrl+H
    • Find what: \R(?=\d{3}\D\h)
    • Replace with: (a space)
    • Replace all

    Explanation:

    \R      : any kind of linebreak (\n or \r or \r\n)
    (?=     : lookahead
      \d{3} : 3 digits
      \D    : a NON-digit
      \h    : a horizontal space
    )       : end lookahead