Insert space before capital letters

前端 未结 8 1183
误落风尘
误落风尘 2020-12-02 07:01

I have a string \"MySites\". I want to place a space between My and Sites.

How can I do this in jQuery or JavaScript?

8条回答
  •  执笔经年
    2020-12-02 07:54

    regex to find lower case - upper case boundary then insert a space

    ThisIsMySites
    $('#x').text( $('#x').text().replace(/([a-z])([A-Z])/g, "$1 $2") );

    http://jsfiddle.net/uXy64/

提交回复
热议问题