我想获得管道分隔字符串的单个字符串,支持“管道转义”,例如:
fielda|field b |field\|with\|pipe\|inside
会得到我:
array("fielda", "field b ", "field|with|pipe|inside")
我如何使用正则表达式实现该目标?
最佳答案
Split by this (?<!\\)\|
查看演示。lookbehind 确保 |
不在 \
之后。
https://regex101.com/r/pM9yO9/15
https://stackoverflow.com/questions/28200875/