JS正則表達式:全文單詞首字母大寫正則表達式
function ReplaceFirstUper(str) { str = str.toLowerCase(); return str.replace(/\b(\w)|\s(\w)/g, function(m){ return m.toUpperCase(); }); } console.log(ReplaceFirstUper('i have a pen, i have an apple!'));