let str = 'hl-swiper-item' // 找到 -字母 改为 -转成大写 str = str.replace( /\-[a-z]/g, function ( _, g ) { return _.split('-').join('').toUpperCase() }) // 此时打印出 hlSwiperItem console.log( str ) // 找到大写字母 改为 -转成小写 str = str.replace(/[A-Z]/g, function ( _, g ) { return '-' + _.toLowerCase() }) console.log( str )