- code
- 常见正则含义
code
// 驼峰转连接符
let str = 'afdsDDfdfLd'
let t = str.replace(/[A-Z]/g,function(match) {
return '-' + match.toLowerCase()
})
console.log(t)
// 连接符转驼峰
let str = 'aadf-asdf-adf'
str = str.replace(/\-[a-z]/g,function(match) {
console.log(match)
return match.slice(1).toUpperCase()
})
console.log(str)
常见正则
- \w:匹配数字字母下划线,\W相反
- \d:匹配数字,\D相反
- \s:匹配空白福,\S相反非空白符
- \b:匹配边界,\B相反
- .匹配换行符外任意一个字符