I’ve a json string. I would like to replace all instances of:
...
...
"style":[["1","2"]]
...
"style":["1"]
...
"style":[["1","3","5","8"]]
to:
...
...
"style":["1","2"]
...
"style":["1"]
...
"style":["1","3","5","8"]
How can I do it?
>Solution :
For best results, you should probably use a JSON parser. If all style keys would always be either singly or doubly nested arrays of strings, then a regex replace all might be sufficient:
String input = "\"style\":[[\"1\",\"3\",\"5\",\"8\"]]";
String output = input.replaceAll("\"style\":\\s*\\[\\[(.*?)\\]\\]", "\"style\":[$1]");
System.out.println(output); // "style":["1","3","5","8"]