[英]How to replace escape characters in a string JavaScript
I'm using Cheerio to get HTML from a local news website.我正在使用 Cheerio 从本地新闻网站获取 HTML。 When it returns the response, it keeps the escape literals (
\\n, \\t
, etc.) in the string.当它返回响应时,它会在字符串中保留转义文字(
\\n, \\t
等)。 Is there a way to use JS regex to replace all of these characters?有没有办法使用 JS 正则表达式来替换所有这些字符? I've tried using the
replace()
function but it doesn't seem to replace all of them.我试过使用
replace()
函数,但它似乎并没有替换所有这些。
Example of the title of the news article I receive back (in json form): " \\n\\t\\t\\t\\t\\t\\t\\t\\t\\t
[news article title here] \\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t
:我收到的新闻文章标题示例(以 json 形式):"
\\n\\t\\t\\t\\t\\t\\t\\t\\t\\t
[此处的新闻文章标题] \\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t
:
Expected output: "[news article here]"预期输出:“[此处的新闻文章]”
Thanks.谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.