Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var countre = /[\w\u2019\x27\-]+/g,
- cleanre = /[0-9.(),;:!?%#$?\x27\x22_+=\\\/\-]*/g;
- function wordCount(tx)
- {
- var tc = 0;
- if (tx) {
- tx = tx.replace(/\.\.\./g, ' '); // convert ellipses to spaces
- tx = tx.replace(/<.[^<>]*?>/g, ' ').replace(/ | /gi, ' '); // remove html tags and space chars
- // deal with html entities
- tx = tx.replace(/(\w+)(&.+?;)+(\w+)/, "$1$3").replace(/&.+?;/g, ' ');
- tx = tx.replace(cleanre, ''); // remove numbers and punctuation
- var wordArray = tx.match(countre);
- if (wordArray) {
- tc = wordArray.length;
- }
- }
- return tc;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement