Skip to content

Instantly share code, notes, and snippets.

@AoiYamada
Last active September 30, 2018 21:17
Show Gist options
  • Save AoiYamada/f7a22f637ce9be57efc30b1f7aead45c to your computer and use it in GitHub Desktop.
Save AoiYamada/f7a22f637ce9be57efc30b1f7aead45c to your computer and use it in GitHub Desktop.
Remove html tag, css, js of html string to extract the contents
/**
* Remove html tag, css, js of html string to extract the contents
* @param {String} html
* @return {String} contents of the html
*/
function extractContents(html) {
return html
.replace(/(\n|\r|\t)/gm, '') // remove linebreaks
.replace(/<(style|script|link|noscript).*?>.*?<\/(style|script|link|noscript)>/g, '') // remove css, js blocks
.replace(/<!--.*?-->/g, '') // remove comments
.replace(/<.*?>/g, '') // remove tags
.replace(/[\s\!\@\#\$\%\^\&\*\(\)\_\+\-\=\{\}\[\]\:\"\;\'\<\>\?\,\.\/\|\\\`\~]+/g, ' ') // remove symbols
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment