📌  相关文章
📜  将每个单词的第一个字母大写 javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:28.756000             🧑  作者: Mango

代码示例3
text.replace(/(^\w|\s\w)/g, m => m.toUpperCase());
// Explanation:
// 
// ^\w : first character of the string
// | : or
// \s\w : first character after whitespace
// (^\w|\s\w) Capture the pattern.
// g Flag: Match all occurrences.

// Example usage:

// Create a reusable function:
const toTitleCase = str => str.replace(/(^\w|\s\w)/g, m => m.toUpperCase());

// Call the function:
const myStringInTitleCase = toTitleCase(myString);