How to split a string into only two parts, by the last occurrence of the split char?

前端 未结 10 1453
猫巷女王i
猫巷女王i 2020-12-29 01:22

For example:

\"Angry Birds 2.4.1\".split(\" \", 2)
 => [\"Angry\", \"Birds 2.4.1\"] 

How can I split the string into: [\"Angry Bir

10条回答
  •  庸人自扰
    2020-12-29 01:48

    Something like this maybe ? Split where a space is followed by anything but a space till the end of the string.

    "Angry Birds 2.4.1".split(/ (?=\S+$)/)
    #=> ["Angry Birds", "2.4.1"]
    

提交回复
热议问题