bigcat
bigcat

Reputation: 152

regex remove line breaks after any but specific characters

I have a csv file with semicolons separator and I need to remove all the line breaks after any character but ; and ".

I have succeeded in finding positions but removing line breaks doesn't seem to work.

What I have:

100138;"Some data";"AB";"My text goes here";
100139;"Some data 2";"CH";"My text goes here";
100140;"Some data 3";"CH";"My text goes here
And it has new line here
But it is still part of quoted data
and ends here";
100141;"Some data 4";"CH";"Another nice text without semicolon"enter

What I need:

100138;"Some data";"AB";"My text goes here";
100139;"Some data 2";"CH";"My text goes here";
100140;"Some data 3";"CH";"My text goes here And it has new line here But it is still part of quoted data and ends here";
100141;"Some data 4";"CH";"Another nice text without semicolon"enter

I used (?<=[^("|;)])$ to find it but \n doesn't seem to change anything. I use notepad++ for that.

Upvotes: 1

Views: 3794

Answers (2)

Toto
Toto

Reputation: 91373

Have a try with:

Find what: (?<![;"])\R
Replace with: NOTHING

This will replace all linebreaks that aren't preceeded by ; nor ".

Upvotes: 0

user694733
user694733

Reputation: 16033

$(?<=[^;])(?<=[^"])\R

  • $ Find end of line
  • (?<=[^;]) Must not end with ;
  • (?<=[^"]) Must not end with "
  • \R Match linebreak character(s)

Upvotes: 1

Related Questions