JSFiddle - React, Tailwind, and code Playground

HTML

<div id="a">
  <p>
    word1 word2 word3.
  </p>
  <p>
    word4 word5 word6?
  </p>
</div>

JavaScript

alert($('#a').text().replace(/(\w)([\.\?\,])/g, '$1 $2').match(/\S+/ig).length)