如何替换\\ r \\ n [复制]

时间:2022-07-20 09:37:10

This question already has an answer here:

这个问题在这里已有答案:

I have a string with several "\r\n" and I'm not sure how to replace it due to the several '\'. With normal '\r\n' I would do that

我有一个带有几个“\ r \ n”的字符串,我不知道如何更换它,因为有几个'\'。正常'\ r \ n'我会这样做

'some string \r\n' here'.replace(/\r\n/g, 'wtv');

But for this one I'm not sure:

但是对于这个我不确定:

// failed attempt below :(
'some string \\r\\n here'.replace('/\\r\\n/g', 'wtv);

1 个解决方案

#1


1  

You can use following code :

您可以使用以下代码:

console.log("some string \\r\\n here".replace(/(?:\\[rn])+/g, "wtv"));

above code will replace all '\r\n' with 'wtv' in your string

上面的代码将用字符串中的'wtv'替换所有'\ r \ n'

#1


1  

You can use following code :

您可以使用以下代码:

console.log("some string \\r\\n here".replace(/(?:\\[rn])+/g, "wtv"));

above code will replace all '\r\n' with 'wtv' in your string

上面的代码将用字符串中的'wtv'替换所有'\ r \ n'