I have a String in Java. Here is the part of it that I'm concerned with {3: {108:TR2011052300088}}
Later on I do a split on {3: {108:. For some reason (I've been googling) { and } is a special character so it has to be escaped \} and \{ (clearly this doesn't work -> compile time error).
Others mention this is some bug in Java regex. I'm not sure really. The exception I get is:
Exception in thread "main" java.util.regex.PatternSyntaxException: Unclosed counted closure near index 2 {3:{108: at java.util.regex.Pattern.error(Unknown Source)
Long story short, my code splits the string using {3: {108: as the separator and crashes on it:
String query="{3: {108:";
String [] messageParts = message.split(query);
I am aware of other ways to do it, albeit more complicated, like writing my own parser and such.
How can I do my string split and not have it crash?
EDIT:
To answer some comments:
- Double slashes don't help: \\{ give \{3:\{108:MAMABEARid123}} since 2 slashes become 1
- Escaping with 1 slash won't compile: Invalid Escape sequence
}would help? It's telling you that it's trying to interpret the brackets.\{doesnt work.\\}and\\{"\{"