Convert string to sentence case in javascript

I came up with this kind of RegExp:

var rg = /(^\w{1}|\.\s*\w{1})/gi;
var myString = "hi all, this is derp. thank you all to answer my query.";
myString = myString.replace(rg, function(toReplace) {
    return toReplace.toUpperCase();
});

Leave a Comment