I have a function which capitalises the first letter of each word:
function format(str){
str = str.replace(/\b[a-z]/g, function(letter) {
return letter.toUpperCase();
});
return str;
}
It is also capitalising after an apostrophe:
console.log(format("mark")); //Mark (correct)
console.log(format("mark o'loughlan")); //Mark O'Loughlan (correct)
console.log(format("mark's audi")); //Mark'S Audi (incorect)
Ideally, I'd like it to capitalise after an apostrophe if it's a name (example 2), but not for 's (example 3). How can I fix this? Fiddle here
Edit: I don't think this is a duplicate of this question, as I'm specifically asking about not capitalising 's but after other apostrophe's is ok.