 <p>This is the solution I ended up using:</p> <pre><code>str = 'hi all, this is derp. thank you all to answer my query.'; temp_arr = str.split('.'); for (i = 0; i &lt; temp_arr.length; i++) { temp_arr[i]=temp_arr[i].trim() temp_arr[i] = temp_arr[i].charAt(0).toUpperCase() + temp_arr[i].substr(1).toLowerCase(); } str=temp_arr.join('. ') + '.'; return str; </code></pre>