I want to do an ucwords() in JavaScript on a string of the form: test1_test2_test3 and it should return Test1_Test2_Test3.
I already found an ucwords function on SO, but it only takes space as new word delimiters. Here is the function:
function ucwords(str) {
return (str + '').replace(/^([a-z])|\s+([a-z])/g, function ($1) {
return $1.toUpperCase();
});
Could anyone help?
Just add an underscore to the list of acceptable word breaks:
As you can see ive replace the bit which was
\s+to[\s_]+Live example: http://jsfiddle.net/Bs8ZG/