我有以下字符串:

 161544476293,26220\,1385853403,WLAN-EneTec5,-85,0,0


如何用逗号分隔,但避免\,大小写。

就我而言,上述字符串应拆分为:

161544476293
26220\,1385853403
WLAN-EneTec5
-85
 0
 0


谢谢,

最佳答案

您可以使用negative lookbehind

str.split("(?<!\\\\),");

// OUTPUT: "161544476293", "26220\,1385853403", "WLAN-EneTec5", "-85", "0", "0"


(?<!\\\\) Negative Lookbehind - Assert that it is impossible to match the regex below
\\ matches the character \ literally
, matches the character , literally

08-18 06:50