Regex to split camel case

前端 未结 12 1844
逝去的感伤
逝去的感伤 2020-11-28 23:31

I have a regular expression in JavaScript to split my camel case string at the upper-case letters using the following code (which I subsequently got from here):



        
12条回答
  •  庸人自扰
    2020-11-28 23:43

    My guess is replacing /([A-Z])/ with /([a-z])([A-Z])/ and ' $1' with '$1 $2'

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

    /([a-z0-9])([A-Z])/ for numbers counting as lowercase characters

    console.log("MyCamelCaseStringID".replace(/([a-z0-9])([A-Z])/g, '$1 $2'))

提交回复
热议问题