I\'ve never used a regex before and I am looking to split up a file that has one or more JSON objects, the JSON objects are not separated by a comma. So I need to split them
If your objects aren't more complex than what you show, you may use lookarounds like this :
String[] strs = str.split("(?<=\\})(?=\\{)");
Exemple :
String str = "{id:\"123\",name:\"myName\"}{id:\"456\",name:\"yetanotherName\"}{id:\"456\",name:\"anotherName\"}";
String[] strs = str.split("(?<=\\})(?=\\{)");
for (String s : strs) {
System.out.println(s);
}
prints
{id:"123",name:"myName"}
{id:"456",name:"anotherName"}
{id:"456",name:"yetanotherName"}
If your objects are more complex, a regex wouldn't probably work and you would have to parse your string.