Strsplit 仅按逗号将键拆分为字符串数组,而不按值c拆分#

Strsplit 仅按逗号将键拆分为字符串数组,而不按值c拆分#,strsplit,Strsplit,这是我的字符串,当使用逗号分隔的键值拆分为字符串数组时出现问题 {Yr=2019年,Mth=12月,SeqN=0,UComment=tet,tet1,OComment=test,test1,FWkMth=WK,FSSAFETY=Y,FCUSTCOWT=Y,FNCNRPull=0,FNCNRPush=0,CreatedTime=2020-01-03 06:16:53} 当我尝试使用string.Split(',')时,我得到了“Ucomment=tet”,“tet1”作为单独的数组。 但是我需要用

这是我的字符串,当使用逗号分隔的键值拆分为字符串数组时出现问题

{Yr=2019年,Mth=12月,SeqN=0,UComment=tet,tet1,OComment=test,test1,FWkMth=WK,FSSAFETY=Y,FCUSTCOWT=Y,FNCNRPull=0,FNCNRPush=0,CreatedTime=2020-01-03 06:16:53}

当我尝试使用string.Split(',')时,我得到了“Ucomment=tet”,“tet1”作为单独的数组。 但是我需要用逗号分隔字符串[]

UComment=tet,tet1 OComment=测试,测试1


我尝试过使用正则表达式,(?=([^\“]\“[^\“]\”[^\“]$)”,但它不起作用。

您可以尝试匹配正则表达式模式
\S+\S*=\S*?(?=\S*,\S*\S+\S*=\S*=\S*}$)

这张照片是:

Yr = 2019
Mth = DECEMBER
SeqN = 0
UComment = tet,tet1
OComment = test,test1
FWkMth = WK
FSafety = Y
FCustConsign = Y
FNCNRPull = 0
FNCNRPush = 0
CreatedTime = 2020-01-03 06:16:53
下面是对使用的正则表达式模式的解释:

\S+                        match a key
\s*                        followed by optional whitespace and
=                          literal '='
\s*                        more optional whitespace
.*?                        match anything until seeing
(?=\s*,\s*\S+\s*=|\s*\}$)  that what follows is either the start of the next key/value OR
                           is the end of the input

您的预期输出在这里是什么样子?@tim biegeleisen,这是一个sring数组,它将像“Yr=2019”、“Mth=12月”、“SeqN=0”、“UComment=tet,tet1”
\S+                        match a key
\s*                        followed by optional whitespace and
=                          literal '='
\s*                        more optional whitespace
.*?                        match anything until seeing
(?=\s*,\s*\S+\s*=|\s*\}$)  that what follows is either the start of the next key/value OR
                           is the end of the input