If I have a string such as follows(which happens to look a lot like JSON, coincidentally):
"name" : "Precalculus",
"authors" : ["Blitzer","Stewart"],
"publisher" : { "name" : "McGraw Hill","year" : "2012",
"city" : ["New York","London","Toronto"]
}
How can I split this string by only the commas that do not appear inside either {}
, []
, or " "
so that I would get the following separated strings:
- "name" : "Precalculus"
- "authors" : ["Blitzer","Stewart"]
- "publisher" : { "name" : "McGraw Hill","year" : "2012", "city" : ["New York","London","Toronto"] }
I know the above splitting can be easily done with just a loop that checks whether a given comma is between {}
, []
, or " "
and then selectively splitting but using regular expressions seems like a cleaner option so any help would be appreciated.