Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 486
Rahul Avatar asked Jun 18 '15 06:06

Rahul


Video Answer


1 Answers

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.

like image 140
Matteo Tassinari Avatar answered Oct 18 '22 10:10

Matteo Tassinari