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("\\}\\),\\(\\{");
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments