Javascript Split string on UpperCase Characters

后端 未结 4 1795
后悔当初
后悔当初 2020-12-02 05:58

How do you split a string into an array in Javascript by UpperCase character?

So I wish to split:

\'ThisIsTheStringToSplit\'

into <

4条回答
  •  無奈伤痛
    2020-12-02 06:40

    .match(/[A-Z][a-z]+|[0-9]+/g).join(" ")
    

    This should handle the numbers as well.. the join at the end results in concatenating all the array items to a sentence if that's what you looking for

    'ThisIsTheStringToSplit'.match(/[A-Z][a-z]+|[0-9]+/g).join(" ")
    

    Output

    "This Is The String To Split"
    

提交回复
热议问题