//转化为camel形式
var text = 'border-color-base';
text.replace(/-(\w{1})/g, function (match, chr1) {
return chr1.toUpperCase();
});
//转化为dash形式
var text = 'borderColorBase';
// AAAbb, AbbAA, aBBBa
//比如AAAbb,得到AA_Abb
text.replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2").
replace(/([a-z])([A-Z])/g, "$1_$2").
replace(/_/g, "-").
toLowerCase();
s = "sabcstringabc999"
re = s.replace(/a(b)(c)/g, function (match, chr1, chr2, char3, char4, char5) {
// match : abc
// chr1 : b
// chr2 : c
// chr3 : 1
// chr4 : sabcstringabc999
// chr5 : undefined
});
console.log(re);
s = "sabcstringabc999"
re = s.replace(/abc/g, function (match, index) {
// match : abc
// index : 1
});
//调换位置
s = "human, huang";
s.replace(/(\w+),\s*(\w+)/, "$2,$1");
//RegExp.$1 : human
//RegExp.$2 : huang
var text = '"JavaScript" 非常强大!';
text.replace(/"(\w+)"/g, "[$1]");
//"[JavaScript] 非常强大!"