Rahul
Rahul

Reputation: 379

Replace only "CRLF" in string having both "CRLF" and "LF" line-separator

I have a string containing both "CRLF" and "LF" as line separator.

I want to replace only "CRLF" with " LF" (space and LF) and keeping "LF" as it is.

I know,we can do this using regex, but I have tried few regex from the already existing answers, but not able to resolve.

Please help, I am new to the javascript/jQuery.

Upvotes: 7

Views: 13325

Answers (1)

Matteo Tassinari
Matteo Tassinari

Reputation: 18584

As simple as

the_string.replace(/\r\n/g, "\n");

where \r is the escape sequence for CR and \n is the one for LF and g is a regex modifier to replace all matching instances instead of only the first one found.

Upvotes: 21

Related Questions