I built a Javascript function to make the first letter uppercase. My issue is that I have some words which are like "name_something" and what I want is "Name Something".
I did this:
function toCamelCase(text) {
return text.replace(/\b(\w)/g, function (match, capture) {
return capture.toUpperCase();
}).split(/[^a-zA-Z]/);
}
You can use
[\W_]
to get rid of characters that are not alphanumeric. WhereW
represent characters froma-z
,A-Z
and0-9
So, to make the words capitalise alongside the replace you can do,