Skip to content
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

正则:驼峰 => 短横线 #377

Open
lzxjack opened this issue Jan 12, 2023 · 2 comments
Open

正则:驼峰 => 短横线 #377

lzxjack opened this issue Jan 12, 2023 · 2 comments

Comments

@lzxjack
Copy link
Contributor

lzxjack commented Jan 12, 2023

No description provided.

@lzxjack
Copy link
Contributor Author

lzxjack commented Jan 12, 2023

const changeName = str =>
  str
    .split(/(?=[A-Z])/)
    .join('-')
    .toLowerCase();

@veneno-o
Copy link
Contributor

// 拼接字符 转换 驼峰
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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants