I have a string value as below
String str = {"A":"do not seperate,value","B":"OPM","C":[1,2,"AB",{"1":{"1":2,"2":[1,2]},"2":2}],"D":{"1":1,"2":[{"1":1,"2":2,"3":3},9,10]}};
How can I write a regular expression to capture its elements separated by a comma which is not inside double quotes, square brackets or curly brackets? I want to match and get the elements by doing something like below; using pattern matching.
List<String> list = new ArrayList<>();
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(str);
while (matcher.find()) {
list.add(matcher.group());
}
The elements should be,
"A":"do not seperate,value"
"B":"OPM"
"C":[1,2,"AB",{"1":{"1":2,"2":[1,2]},"2":2}]
"D":{"1":1,"2":[{"1":1,"2":2,"3":3},9,10]}
If the string is something like below
String str = [1,2,{"A":1,"B":2},[19,10,11,{"A":1,"B":2}],100]
Then the elements should be
1
2
{"A":1,"B":2}
[19,10,11,{"A":1,"B":2}]
100