Title Case a Sentence Challenge

Alright, this almost works… I’ve seen others use the .split method as recommended in the challenge, but I almost found another way to do this using a Regex. The issue I’m having is that the \b meta-character is viewing apostrophes as a space, and as a result, it capitalizes the M in I’m. Is there way to stop it from doing this? I’ve tried several combinations using a Regex builder, but to no avail. Here is what I have so far…

function titleCase(str) {
  //Convert all cases to lowercase.
  str = str.toLowerCase();
  //Convert each first letter to uppercase.
  str = str.replace(/\b[a-z]/g, function(letter) {

    return letter.toUpperCase();
  return str;

titleCase("I'm a little tea pot");

You could replace \b with \s (it targets whitespace along with the character, but for capitalizing letters it doesn’t matter) + capitalize first letter of the string by default ( or use if statement, to capitalize it only if it’s an alphabetical character).

I did the same.

[details=Here’s my solution:]

function titleCase(str) {
  var x = function repl(str) {
  return str.toUpperCase();

var y = str.toLowerCase();
var z = y.replace(/(\s\w)|^./g, x);
return z;


titleCase("I'm a little tea pot");