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.
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.
Share Improve this question edited Feb 6, 2016 at 21:14 marc_s 754k184 gold badges1.4k silver badges1.5k bronze badges asked Jun 18, 2015 at 6:46 RahulRahul 3791 gold badge3 silver badges11 bronze badges 3 |1 Answer
Reset to default 21As 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.
var regexp_clean_CRLF = new RegExp("\r\n", "g");
my_string = my_string.replace(regexp_clean_CRLF, " \n")
– Waxo Commented Jun 18, 2015 at 6:55