//第一种方法replace实现
var str = 'hELLO wORLD';
function turn(str){
return str.replace(/\w/g,function(a){
return a.toLowerCase() == a ? a.toUpperCase() : a.toLowerCase();
})
}
console.log(turn(str))
//第二种 replace实现
var str = 'hELLO wORLD';
function turn2(str){
return str.replace(/([a-z]*)([A-Z]*)/g,function($0,$1,$2){
return $1.toUpperCase() + $2.toLowerCase();
})
}
console.log(turn2(str))