I need to replace all \n
with \r\n
, but only if \n
hasn't already \r
previosly.
i.e.
Hello\nGreat\nWorld
-> Hello\r\nGreat\r\nWorld
Hello\r\nGreat\r\nWorld
-> Hello\r\nGreat\r\nWorld
.
In Java i can do it in next way
"Hello\nGreat\nWorld".replaceAll("(?<!\r)\n", "\r\n");
But (?<!X)
construct is absent in JS.
Any ideas, how can I do it in JS?