I need to split text (sql query) by each comma which is not between parenthesis.
Example (I marked commas which should be included in split):
a."Id", //<- this comma
a."Description", //<- this comma
UJsonObject(
fepv."Id", //<- NOT this comma
fepv."SystemName", //<- NOT this comma
string_agg(
translations."Translations", ',' //<- NOT this comma (here can be some nested parenthesis also)
) as "Translations"
) as "Translations", //<- this comma
b."DataSource", //<- this comma
a."Name", //<- this comma
a."Value"
I found universal solution here: https://regex101.com/r/6lQKjP/2 but it appears that this solution is not working in dotnet.
I would like to use Regex.Split, but if this case can be satisfied by Regex.Matches I will be happy too. Also I know I can write my own parser, but I read that simple cases (which not extract nested parenthesis) can be handled via Regex.