0
votes

I am not as familiar with RegEx as I probably should be.
However, I am looking for an expression(s) that matches a variant of values.

My string:

2020/09/10 05:41:02,ABC,888,!"#$%'()=~|{`}*+_?><-^\@[;:]./\,{"data1-1":"48.16","data1-2":"!"#$%'()=~|{`}*+_?><-^\@[;:]./\"}

I am trying to split comma using regular expression to get the result below:

enter image description here

string regex = "," + @"\s*(?![^{}]*\})";
List listResult = Regex.Split(myString, regex).ToList();

The received results are not correct.
Can regular expressions be used in this case?
What could i use to split that string according to every comma outside the { }? Cheers

2

2 Answers

0
votes

I'm not sure how this works with regular expressions. However, instead of using regex, you could just create a list with your delimiters and use the string.split method:

char[] delim = new [] {','}; //in your case just one delimiter
var listResult = myString.Split(delim, StringSplitOptions.RemoveEmptyEntries);

The string.split method returns an array.

0
votes

You can check how comma separated value format (CSV) is usually parsed. Here with a regex : https://stackoverflow.com/a/18147076/6424355

Split using comma is simpler if you don't needs quotes