正则:驼峰 => 短横线
lzxjack opened this issue · comments
const changeName = str =>
str
.split(/(?=[A-Z])/)
.join('-')
.toLowerCase();
// 拼接字符 转换 驼峰
let str = 'hello-world-mihayou';
str = str.replace(/-([a-z])/g,function(text, $1){
return $1.toUpperCase();
})
console.log(str);
// 驼峰 转换 -拼接字符
str = str.replace(/([a-z])([A-Z])/g,function(text, $1, $2){
return $1 + "-" +$2.toLowerCase();
})
console.log(str)