我有这段代码可以删除html元素:
console.log("<p>Done is beautiful. <\/p>\n".replace(/<(?:.|\n)*?>/gm, ''))
但是我很难将regExp删除\ n,这将返回
“我的文字\ n”
如何删除文字上的\ n?
答案 0 :(得分:0)
您只需在正则表达式中使用alternation ( | )
/<(?:.|\n)*?>|\n/
| |________ Matches new line
|__________________ Matches `<` followed by any character followed by `>`
console.log('<p>my text</p>\n some value'.replace(/<(?:.|\n)*?>|\n/gm, ''))