我可以用一个简单的HTML代码来提取它的所有内容。但我只需要使用正则表达式
我已经写了下面的代码,但它有一些错误,我不知道如何解决它。
function htmlToText(html) {
return html.
replace(/(.|\n)*<body.*>/, ''). //remove up till body
replace(/<\/body(.|\n)*/, ''). //remove from </body
replace(/<.+\>/, ''). //remove tags
replace(/^\s\n*$/gm, ''); //remove empty lines
}
这是解决问题的方法
function htmlToText(html) {
return html.
replace(/(.|\n)*<body.*>/, ''). //remove up till body
replace(/<\/body(.|\n)*/g, ''). //remove from </body
replace(/<.+\>/g, ''). //remove tags
replace(/^\s\n*$/gm, ''); //remove empty lines
}