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

前端 未结 5 1249
故里飘歌
故里飘歌 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:00

    Late to answer, but this solution will work for cases where a single letter is camel cased.

    'thisIsATest'.replace(/([a-zA-Z])(?=[A-Z])/g, '$1-').toLowerCase();  // this-is-a-test
    

提交回复
热议问题