Javascript/jQuery: Split camelcase string and add hyphen rather than space

前端 未结 5 1252
故里飘歌
故里飘歌 2020-12-23 11:29

I would imagine this is a multiple part situation with regex, but how would you split a camelcase string at the capital letters turning them in to lowercase letters, and the

5条回答
  •  眼角桃花
    2020-12-23 12:07

    Try something like:

    var myStr = 'thisString';
    
    myStr = myStr.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
    

提交回复
热议问题