I am trying to Capitalize the first letter of each word in a string. I found similar questions online but none seem to answer my question of ignoring Contractions like can't, won't, wasn't.
This snippet of code works but it also capitalizes the letter after the apostrophe in the contraction.
var str = str.replace(/\b\w/g, w => w.toUpperCase())
If the string contains a contraction like can't or won't it will output Can'T or Won'T.
Is there a way to ignore apostrophes that are in the middle of a word? I still want to capitalize words that are separated by other punctuation. For example:
- this_is_an_example -> This_Is_An_Example
- this/is/an/example -> This/Is/An/Example
- this,is,an,example -> This,Is,An,Example