Javascript / jQuery:拆分camelcase字符串并添加连字符而不是空格 [英] Javascript/jQuery: Split camelcase string and add hyphen rather than space
本文介绍了Javascript / jQuery:拆分camelcase字符串并添加连字符而不是空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我认为这是正则表达式的多部分情况,但是如何将大写字母的camelcase字符串拆分为小写字母,然后在每个新字符串之间添加连字符?
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 then adding a hyphen between each new string?
例如:
thisString
thisString
将成为:
this-string
this-string
推荐答案
尝试类似:
var myStr = 'thisString';
myStr = myStr.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
这篇关于Javascript / jQuery:拆分camelcase字符串并添加连字符而不是空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文