Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

请问下面的replace是如何按照大写字母分割字符串的

function spinalCase(str) {

  str = str.replace(/([a-z])([A-Z])/g, '$1 $2');
    console.log(str);
}
spinalCase('ThisIsSpinalTap');

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.7k views
Welcome To Ask or Share your Answers For Others

1 Answer

'ThisIsSpinalTap'.replace(/([A-Z]{1}[a-z]*)/g,'$1 ')

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...