I have the following function that performs multiple replace actions on a single string inputHtml
. It works well but takes too long. Is it possible to speed it up by combining them?
/* Receives HTML code and returns the plain text contained in the HTML code */
function decodeHtml(inputHtml) {
const commentsRemoved = inputHtml.replace(/<!--[\s\S]*?-->/gm, '');
const linebreaksAdded = commentsRemoved.replace(/<br>/gm, '\n');
const tagsRemoved = linebreaksAdded.replace(/<(?:.|\n)*?>/gm, '');
const linebreaksRemoved = tagsRemoved.replace(/^\s*[\r\n]/gm, '');
const plainText = entities.decode(linebreaksRemoved);
return plainText;
}