Split string once in javascript?

前端 未结 13 909
南笙
南笙 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.

    0 讨论(0)
提交回复
热议问题