开发者

Replace [] with () in a String

开发者 https://www.devze.com 2023-03-25 08:19 出处:网络
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 suffic

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)");
0

精彩评论

暂无评论...
验证码 换一张
取 消