Tell us what’s happening:
Hello, I used regex to try and complete this challenge but I’m having an issue since \b is not only counting spaces but also single quotes so instead of what I want to happen which is match I in I’m, It’s matching I and M. Is there anything I can do with my regex or is my approach incorrect?
Your code so far
function titleCase(str) {
let lower = str.toLowerCase();
console.log(lower);
let regex = /\b\w/g;
let str2 = lower.replace(regex, function (x){
return x.toUpperCase();
});
return str2;
}
titleCase("I'm a little tea pot");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36
.
Link to the challenge: