How can I split a string using [
as the delimiter?
String line = "blah, blah [ tweet, tweet";
if I do
line.split("[");
I get an error
Exception in thread "main" java.util.regex.PatternSyntaxException: Unclosed character class near index 1 [
Any help?
The [
is a reserved char in regex, you need to escape it,
line.split("\\[");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With