DEV Community

Discussion on: Web Basics: How to Capitalize a Word in JavaScript

 
qm3ster profile image
Mihail Malo • Edited

OH NO

'mi ke$ha'.toLowerCase().replace(/\b\w/gi, c => c.toUpperCase())
//> "Mi Ke$Ha"

:'(

Thread Thread
 
diek profile image
diek

That was expected, which result do you wanted?

Thread Thread
 
qm3ster profile image
Mihail Malo

Try my honestly unironically inferior regex and see:

'mi ke$ha'.toLowerCase().replace(/(?:^|\s)\w/g, c => c.toUpperCase())