Split string on the first white space occurrence

后端 未结 13 2008
孤街浪徒
孤街浪徒 2020-11-28 20:07

I didn\'t get an optimized regex that split me a String basing into the first white space occurrence:

var str=\"72 tocirah sneab\";

I need

13条回答
  •  自闭症患者
    2020-11-28 20:45

    You can also use .replace to only replace the first occurrence,

    ​str = str.replace(' ','
    ');

    Leaving out the /g.

    DEMO

提交回复
热议问题