Using Regex to remove carriage returns in a CSV file in Notepad ++

I have a CSV file that needs to be cleaned. This is a one-time thing, so I would like to do it in Notepad ++, if possible.

The CSV file has two fields, one of which is enclosed in quotation marks. I would like to remove any carriage returns from the field specified in the field. I tried to use this template, but I can not understand it correctly ...

(.*)\"(.*)\n(.*)\"(.*)

Also correct me if I am wrong, but I believe the value of "replace with" would be as follows:

\1\2\3\4

Thanks in advance.

I am also open to alternative solutions, such as a quick and dirty PERL script.

+3
source share
8 answers

StackOverflow , , . PERL. ! , , , .

, , . !

$string123 =~ s/((?:^[^"]*"|(?!^))[^"]*?(?:"[^"]*"[^"]*?)*?)(\n{1,})/$1/g; 
+2

, , -, , , , , Perl.

, . , Perl , \n, , /x 0D.


, :

$string123 = ~ s/((?: ^ [^ "]" | (?! ^)) [^ "]? (?:" [^ "]" [^ "]?)?) (\n {1,})/$1/g;


:

$string123 = ~ s/((?: ^ [^ "]" | (?! ^)) [^ "]? (?:" [^ "]" [^ "]?)?) (\x0D {1,})/$1/g;

, !

+1

- ++, :

/show invisible characters CR LF.

, csv ( , ) LF. CR IN IT. , , , , , CR/LF ( , CR LF)!

, . CRLF, f & r, "find what:" CRLF. .

TADA! , .

+1

Notepad ++. Shreyas , , \r\n . :

[^"]"(([^"]*)\r\n([^"]*))+"

, , , :

[somethin0]"[somethin1]NEWLINE[somethin2]"

somethin1 somethin2 are\2 \3 (\1 - ), somethin0 - ( , ). , , :

[somethin0]"\2 \3"

! , . Single replace . replaceAll ( " " - , )

+1

Notepad ++ , \n \t. , - .

Eclipse, .

,

\n , # .

,

, \n

0

π, . char. Ctr + H

Hope this works for you.

0
source

Well ... my RegEx is terrible and I can't answer your question. However, here is a small JS function that you can use that should be able to do what you want.

function removeNewLines(str){
    var quotedStrings = str.split(/["'](.*)?["']/g),
        i = 0;

    for( ; i < quotedStrings.length; i++){
        str = str.replace(quotedStrings[i], quotedStrings[i].replace(/[\r\n]/g,""));
    }
    return str;
}
removeNewLines("\"asdf\r\nas\"asdf\'as\nd\'asdf\"asdf\r\nasf\r\n\"") === "\"asdfas\"asdf'asd'asdf\"asdfasf\"";
0
source

Here is an answer specifically for Notepad ++

Menu: TextFX > TextFX Edit > DeleteEmpty Lines

This menu item has the option Delete extra lines.

0
source

Source: https://habr.com/ru/post/1711112/


All Articles