简体   繁体   中英

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM