Kodakgold Kodakgold - 2 years ago 101
Javascript Question

Trying to remove extra lines break in a CSV-like string using Javascript and Regexp

I have a string in a textarea, representing a CSV file :

6166;14/12/2011;CASTANIE Bernard;11, rue Porte Bouqueyre;;33330;;Pose d'un radiateur dans la véranda.;44.31;
6167;14/12/2011;CASTANIE Bernard;11, rue Porte Bouqueyre;;33330;;Dépannage de la chaudière DE DIETRICH MCR 24.;50.23;
6301;07/02/2012;SCI DU MANOIR;Le Manoir - BP 33;;33330;jfxxxxxxx@gmail.com;"DEPANNAGE PLOMBERIE
Intervention R12020023 du 20/01/12";895.16;
6302;07/02/2012;SCI DU MANOIR;Le Manoir - BP 33;;33330;jfxxxxxxx@gmail.com;"DEPANNAGE PLOMBERIE WC des bureaux.
Intervention R12020024 du 23/01/12";92.86;

Some of these lines have a line break in the fields.

What would be the regex that I could use in Javascript to remove them and only keep the last line break?

I tried this but it doesn't work :


Big thanks in advance!


Answer Source

Replace all newlines which are not preceded by semicolon:

myString.replace(/([^;])\n/g, '$1 ')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download