I am trying to uppercase the first letter of each word in a sentence.
In javascript, \b
seems to be intended for that : it matches the beginning of a word.
This works with ascii characters :
static capitalize(str: string): string {
return str.replace(new RegExp('\\b\\w', 'g'), (txt) => txt.toUpperCase());
}
This test passes :
expect(StringUtils.capitalize('jean-michel dupont')).toEqual('Jean-Michel Dupont');
Problem : when I use latin characters, the latin character and the next character are uppercased.
StringUtils.capitalize('Fais de ta vie un rêve, et d\'un rêve, une réalité.')
Fais De Ta Vie Un RÊVe, Et D'un RÊVe, Une RÉAlité. // Actual
Fais De Ta Vie Un Rêve, Et D'Un Rêve, Une Réalité. // Expected
Is there an option to handle that ?