TL;DR
You want:
.split("\], \[")`
Escape each square bracket twice — once for each context in which you need to strip them from their special meaning: within a Regular Expression first, and within a Java String secondly.
Consider using Pattern#quote
when you need your entire pattern to be interpreted literally.
Explanation
String#split
works with a Regular Expression but [
and ]
are not standard characters, regex-wise: they have a special meaning in that context.
In order to strip them from their special meaning and simply match actual square brackets, they need to be escaped, which is done by preceding each with a backslash — that is, using [
and ]
.
However, in a Java String,
is not a standard character either, and needs to be escaped as well.
Thus, just to split on [
, the String used is "\["
and you are trying to obtain:
.split("\], \[")
A sensible alternative
However, in this case, you're not just semantically escaping a few specific characters in a Regular Expression, but actually wishing that your entire pattern be interpreted literally: there's a method to do just that ??
Pattern#quote
is used to signify that the:
Metacharacters [...] in your pattern will be given no special meaning.
(from the Javadoc linked above)
I recommend, in this case, that you use the following, more sensible and readable:
.split(Pattern.quote("], ["))
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…