title: Count sentences in string with JavaScript
body: <p>There are already a couple of similar questions:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/11111801/splitting-textarea-sentences-into-array-and-finding-out-which-sentence-changed-o">Splitting textarea sentences into array and finding out which sentence changed on keyup()</a></li>
  <li><a href="https://stackoverflow.com/questions/27630408/js-regex-to-split-text-into-sentences">JS RegEx to split text into sentences</a></li>
  <li><a href="https://stackoverflow.com/questions/11761563/javascript-regexp-for-splitting-text-into-sentences-and-keeping-the-delimiter">Javascript RegExp for splitting text into sentences and keeping the delimiter</a></li>
  <li><a href="https://stackoverflow.com/questions/18914629/split-string-into-sentences-in-javascript">Split string into sentences in javascript</a></li>
  </ul>
  
  <p>My situation is a bit different.</p>
  
  <p>I need to <strong>count</strong> the number of sentences in a string.</p>
  
  <p>The closest answer to what I need would be:</p>
  
  <pre><code>str.replace(/([.?!])\s*(?=[A-Z])/g, "$1|").split("|")
  </code></pre>
  
  <p>The only problem here is that this RegEx assumes a sentence starts with a capital letter, which may not always be the case.</p>
  
  <p>To be more specific, I would define a sentence as:</p>
  
  <ul>
  <li>Starting with a letter (capital or not), a number or even a symbol (such as $ or €).</li>
  <li>Ending with a punctuation sign, such as a " . ", a " ? " or a " ! ".</li>
  </ul>
  
  <p>However, if a sentence contains a number, which itself contains a " . " or a " , ", then the sentence should be considered as one sentence and not two.</p>
  
  <p>Last but not least, we can assume that, except the first sentence, a sentence is preceded by a space.</p>
  
  <p>Given a random string, how can I count the number of sentences it contains with Javascript (or CoffeeScript for that matter)?</p>