How to split a string with the character "[" using split() in java
I am not able to give 开发者_开发技巧"[" directly as it considers it as char set. If i try giving "[" , i get a error saying escape sequence is not possible for "[".
Escape it with a double backslash:
\\[
This is needed to stop the regex engine treating the [
as the start of a character class.
The first backslash is needed since the \\[
is part of a string literal; only the second backslash will make it to the regex engine. In other words, the regex engine will see the above as \[
.
org.apache.commons.lang.StringUtils.split( src, '[' )
Done. Why are you wasting time on this?
精彩评论