I am trying to perform a split similar the following:
String str = "({Somestring 1 with a lot of braces and commas}),({Somestring 12with a lot of braces and commas})";
println str.split("}),({");
But i see:
java.util.regex.PatternSyntaxException: Unmatched closing ')' near index 0 }),({
Clearly , my string is being treated as a regular expression.
Is there a way i can escape this string?
the character (
and )
and {
and }
are special character in regexp. you have to escape these:
println str.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