I am trying to capitalize the first word of a string
function titleCase(str) {
var newStr = str.split(" ");
//TeSt 10 array newStr
for (var i = 0; i < str.length; i++) {
//
(newStr[i][0].replace(new RegExp("[a-z]"), new RegExp("[A-Z]")))
}
}
titleCase("I´m a little tea pot")
I am very confused about Regex so the code I know is wrong but I´d like to know if it's possible to do it as closely similarly like this. So basically once the first letter of each word has been located (newStr[i][0]) I want to .replace(the noncaps to caps)
.
I know the RegExp
is probably very wrong, but, could something like this work? Combining replace and instead of putting the literal string you want to replace (because that is already done in newStr[i][0]
) doing it with Regex