javascript - Issues with fullstops in word count script -


i have following code text div id para has last word , first word of next sentence joined , views 1 word instead of 2

code:

var value = $('#richhtmlfield_displaycontent').text();  console.log("text", value)      if (value.length == 0) {         $('#show_word_count').html(0);         return;     }      var wordcount = value.match(/\s+/ig).length       $('#show_word_count').html(wordcount);     };  $(document).ready(function() {         $('#richhtmlfield_displaycontent').change(counter);         $('#richhtmlfield_displaycontent').keydown(counter);         $('#richhtmlfield_displaycontent').keypress(counter);         $('#richhtmlfield_displaycontent').keyup(counter);         $('#richhtmlfield_displaycontent').blur(counter); }); 

so want add space after full stops, question marks count total word.

if replace ths "s" in regular expression "w" search words instead . see below -

function wordcount() {    var value = document.getelementbyid("text").value;    document.getelementbyid("result").innertext = value.match(/\w+/ig).length;  }    wordcount();
<textarea id="text">some text. here!</textarea>  <div id="result"></div>  <button onclick="wordcount()">word count</button>

this match string of letters or numbers (including underscores).

for more in-depth discussion of regular expressions check out question , mozilla developer network.


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -