I’m not strong in regex, so any help would be appreciated.
I need to parse such strings:
["text", "text", ["text",["text"]],"text"]
And output should be (4 strings):
text, text, ["text",["text"]], text
I’ve tried this pattern (\\[[^\\[,^\\]]*\\])|(\"([^\"]*)\"):
String data="\"aa\", \"aaa\", [\"bb\", [\"1\",\"2\"]], [cc]";
Pattern p=Pattern.compile("(\\[[^\\[,^\\]]*\\])|(\"([^\"]*)\")");
But output is (quotes themselves in output are not so critical):
"aa", "aaa", "bb", "1", "2", [cc]
How to improve my regex?
I’m not sure regex are able to do that kind of stuff on their own. Here is a way to do it though:
Output:
PS: the code seems complex ’cause commented. Here is a more concise version:
Call: