title: javascript regex for counting words
body: <p>I got this code for counting the number of words from an html editor.</p>
  
  <pre><code>(providing htmlData has already been set)
  var rawWords = htmlData.replace(/&lt;(?:.|\s)*?&gt;/g, '')
                         .replace(/(\r\n|\n|\r)/gm,' ');
  var filteredWords = rawWords.replace(/\[([^\]]+)\]/g,'')
                              .replace(/\s+/g, " ")
                              .replace(/^\s+|\s+$/g, "");
  </code></pre>
  
  <p>From what I understand, the first line removes the html and then removes any returns.</p>
  
  <p>The next line removes anything in brackets (this is to add notes without affecting the word count) and then removes extra spaces</p>
  
  <p>But if I type this:</p>
  
  <pre><code>Apple
  
  
  Charlie
  
  Tom
  </code></pre>
  
  <p>It gives me a word count of 6, not 3. Any idea why? I'm not good at regex!!!!</p>
  
  <p>thanks so much</p>