用于解析具有括号的复杂CSV的正则表达式

时间:2022-10-30 00:23:08

I need to parse a csv like this -

我需要像这样解析一个csv -

[{a,b,c},{d,e,f},{g,h,i}]

I just need the data between () and then parse it again to get actual values.

我只需要()之间的数据,然后再次解析它以获得实际值。

I am able to fetch (a,b,c) | (d,e,f) etc. using this regEx - {[^}]*?}

我能够获取(a,b,c)| (d,e,f)等使用此regEx - {[^}] *?}

How can I get just a,b,c and d,e,f as groups?

我怎样才能得到a,b,c和d,e,f作为群组?

2 个解决方案

#1


1  

use look-ahead and look-behind in the regex like this (?<={)[^}]*?(?=}) this will get you only a,b,c type values in groups

像这样在正则表达式中使用前瞻和后瞻(?<= {)[^}] *?(?=})这将只获得组中的a,b,c类型值

#2


0  

{([^}]*?)}

then you can get a,b,c with m.Groups[1]

然后你可以用m.Groups获得a,b,c [1]

#1


1  

use look-ahead and look-behind in the regex like this (?<={)[^}]*?(?=}) this will get you only a,b,c type values in groups

像这样在正则表达式中使用前瞻和后瞻(?<= {)[^}] *?(?=})这将只获得组中的a,b,c类型值

#2


0  

{([^}]*?)}

then you can get a,b,c with m.Groups[1]

然后你可以用m.Groups获得a,b,c [1]