使用管道转义匹配管道分隔字符串的正则表达式 [英] regular expression to match pipe separated strings with pipe escaping

查看:24
本文介绍了使用管道转义匹配管道分隔字符串的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得管道分隔字符串的单个字符串,支持管道转义",例如:

I'd like to get the single strings of a pipe-separated string, with "pipe escaping" support, e.g.:

fielda|field b |field\|with\|pipe\|inside

会让我:

array("fielda", "field b ", "field|with|pipe|inside")

我如何使用正则表达式达到这个目标?

How would I reach that goal with a regular expression?

推荐答案

Split  by this (?<!\\)\|

查看演示.后视确保 | 不在 \ 之后.

See demo.The lookbehind makes sure | is not after \.

https://regex101.com/r/pM9yO9/15

这篇关于使用管道转义匹配管道分隔字符串的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆