Replace [] with () in a String
How can I change a String like this:
[a,b,c]
to this:
(a,b,c)
开发者_开发百科
I want to use Java's regular expressions.
If your problem is just these parentheses, something like this could suffice:
s.replaceAll("\\[", "(").replaceAll("\\]", ")")
Actualy you can do this by invoking replaceAll once
"[a, b, c]".replaceAll("\\[([^\\]]+)\\]", "($1)");
精彩评论