The code is very simple to apply regular expressions to convert upper and lower case in js.
The following initial letters are capitalized, other letters are lowercase
<script type="text/javascript"> function replaceReg(reg,str){ str = str.toLowerCase(); return str.replace(reg,function(m){return m.toUpperCase()}) } var reg = //b(/w)|/s(/w)/g; var str = 'share javascript'; var str2 = 'SHARE JAVASCRIPT'; var str3 = 'Test /n str is no good!'; var str4 = 'final test'; document.write(replaceReg(reg,str)+'<br />'); document.write(replaceReg(reg,str2)+'<br />'); document.write(replaceReg(reg,str3)+'<br />'); document.write(replaceReg(reg,str4)+'<br />'); document.write(replaceReg(reg,str4)+'<br />'); </script>The following is only the capital letter of the first letter, and other letters are not processed in upper and lower case.
<script language="JavaScript"> <!-- var str="xi nAn shi you xUe yuan china people" alert(str.replace(//s[az]/g,function($1){return $1.toLocaleUpperCase()}).replace(/^[a- z]/,function($1){return $1.toLocaleUpperCase()})) //--> </script>Run the code and just look at the effect!