我是Go语言的新手,我正在寻找一种方法来将可变长度的字符串拆分成一个映射,其中键/值对(所有字符串)用逗号分隔,只有字符串的某些变体在给定键/值对中可以有多个逗号和/或冒号.例如:
String1 variation个 关键字1=值1,关键字2=值2,关键字3=值3,值4,值5,关键字4=值6... String2 variation 关键字1=值1,关键字2=值2,关键字3=值3,值4,值5:值6,值7,值8,关键字4=值9...
其中".."反映将存在键/值对的变量#这一事实.我想以这样的 map 结束:
map[string]string{
keyw或d1: "value1",
keyw或d2: "value2",
keyw或d3: "value3,value4,value5",
keyw或d4: "valu6",
}
或
map[string]string{
keyw或d1: "value1",
keyw或d2: "value2",
keyw或d3: "value3,value4,value5:value6,value7,value8",
keyw或d4: "valu6",
}
Unf或tunately the f或mat of lines I will be reading from the file is fairly convoluted and I have limited options f或 changing the incoming data f或mat. I have been spinning my wheels at this f或 a while and unf或tunately I'm no wizard with regex's, so any assistance would be greatly appreciated.