Split string once in javascript?

前端 未结 13 1007
南笙
南笙 2020-11-29 03:23

How can I split a string only once, i.e. make 1|Ceci n\'est pas une pipe: | Oui parse to: [\"1\", \"Ceci n\'est pas une pipe: | Oui\"]?

The

13条回答
  •  醉话见心
    2020-11-29 03:58

    use the javascript regular expression functionality and take the first captured expression.

    the RE would probably look like /^([^|]*)\|/.

    actually, you only need /[^|]*/ if you validated that the string is formatted in such a way, due to javascript regex greediness.

提交回复
热议问题