I want to parse nested JSON strings by splitting them up recursively by { }. The regex I came up with is "{([^}]*.?)}", which I've tested appropriately grabs the string I want. However, when I try to include it in my Java I get the following error: "Invalid escape sequence (valid ones are \b \t \n \f \r \" \' \ )"
This is my code, and where the error occurs:
String[] strArr = jsonText.split("\{([^}]*.?)\}");
What am I doing wrong?
解决方案
1. Curle braces have no special meaning here for regexp language, so they should not be escaped I think.
If you want to escape them, you can. Backslash is an escape symbol for regexp, but it also should be escaped for Java itself with second backslash.
Why don't you escape curle brace inside grouping construct?
You are using reluctant quantifier, so it won't work with nested braces, for example for {"a", {"b", "c"}, "d"} it will match {"a", {"b", "c"}