Created
March 8, 2017 20:07
-
-
Save armincifuentes/bd1a06913e535c6e1d6a663b15c4d6e1 to your computer and use it in GitHub Desktop.
Count words in a HTML text body
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function wordCount(text) { | |
return text | |
.replace(/[–,;.:!¡¿\-\?\(\)]/g, '') // remove punctuation | |
.replace(/<[^>]+>/g, ' ') // convert tags into whitespaces | |
.split(/\s/) // split across whitespaces | |
.filter(word => word.length) // remove empty keys | |
.length; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment