Routine to remove extra newline chars and carriage return

N

noagbodjivictor

You can write one:

String.prototype.rtrim = function() {
return this.replace(/\n\r/,"");
}
 
S

scripts.contact

You can write one:

String.prototype.rtrim = function() {
return this.replace(/\n\r/,"");}

String.prototype.rtrim = function() {
return this.replace(/[\n\r]/,"");
}
 
B

Bart Van der Donck

scripts.contact said:
You can write one:
String.prototype.rtrim = function() {
return this.replace(/\n\r/,"");}

String.prototype.rtrim = function() {
return this.replace(/[\n\r]/,"");}

No. The three most common EOLs are:

\n (Linefeed)
\r (Carriage return)
\r\n (Carriage return followed by linefeed)

But you also have:

NEL = Next Line (\u0085)
FF = Form Feed (\u000C)
LS = Line Separator (\u2028)
PS = Paragraph Separator (\u2029)

A fully backwards compatible, Unicode-compliant regexp would be:

/(\r\n|\r|\n|\u0085|\u000C|\u2028|\u2029)/g
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top