javascript - Finding how many times a capital letters precede a period -


i need count how many letters capital precede period. find each period , check character before see if capital.

here code threw thought job.

var s = 'washington d.c. nice place.'; var counter = 0; var totals = 0; var n = s.indexof(".",counter); var times = s.split('.').length;  var l = n; while(counter != times){   n = s.indexof(".",l);   if(s.substring(n-1,1) == s.substring(n-1,1).touppercase())   totals++;   counter++;   l = n; } //totals should 2 

this worked me:

var s = 'washington d.c. nice place.'; var foo = s.match(/[a-z]\./g,s); console.log(foo.length); 

jsfiddle example


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -