-
-
Notifications
You must be signed in to change notification settings - Fork 241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
正则 驼峰转换 #54
Comments
const changeName = str => str.replace(/-([a-z])/g, (all, char) => char.toUpperCase()); |
str.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); // helloWorld => hello-world
str.replace(/-([a-z])/g, function(match, group1) {
return group1.toUpperCase();
});
// hello-world => helloWorld |
// 拼接字符 转换 驼峰
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The text was updated successfully, but these errors were encountered: