Split string by delimiter, but not if it is escaped

前端 未结 5 1584
旧巷少年郎
旧巷少年郎 2020-11-27 10:58

How can I split a string by a delimiter, but not if it is escaped? For example, I have a string:

1|2\\|2|3\\\\|4\\\\\\|4

The delimiter is <

5条回答
  •  暖寄归人
    2020-11-27 11:26

    Recently I devised a solution:

    $array = preg_split('~ ((?

    But the black magic solution is still three times faster.

提交回复
热议问题