Click here to Skip to main content
15,886,091 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
I have a text file that I want to split with RegEx, but the problem is that its syntax is something like this:
["string", "string", [("string", int),("string", int)], int, int, string(int, "string")],

I want to split it using the comma (,) as a delimiter, but as you can see, there are a lot of other commas that I don't want to split (In the example - the ones between () brackets). I tried to use lookarounds, but it didn't work. I'm fairly new to Regular Expressions, so I wanted to ask: Is there a way to determine if the comma is between brackets (but not next to them...) and split using only the bracket-free commas?
Posted

I wrote an article about string splitting you might be interested in. It wouldn't do exactly what it looks like you need, but it might provide a starting point.

Persistent String Parser[^]
 
Share this answer
 
I found it. I just implement a parser which check every char in the specified string for a comma. If the comma is not between brackets and stuff, I accept it as a delimiter and split with it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900