DEV Community

Discussion on: Capitalize first letter in every sentence?

Collapse
 
daxsoft profile image
Michael Willian Santos • Edited

Well, try to regex: (good site to practice is regex101.com/)

const capitalizeFirstLetters = (str) => str.replace(/(\b([a-z]))/gi, (str) => str.toUpperCase())

Now, some funny but not recommendend for this case alone:

const funnyWay = str => str.split(/\b/gi).map(char => char.replace(/^\w{1}/i, (letter) => letter.toUpperCase())).join('')