Reputation: 441
Hi to all coders out there. Let me do this straight.
I want to replace all character in a string inside a opening and closing brackets.
what I have in my code.
string value= str.replaceAll("\\[.*\\]", "strToReplace");
It's working , but the problem is it also delete the brackets.
ex:
I want to say [Hello].
the result:
I want to say .
How can I achieve that? Anyone? Thanks in Advance. It will be a really big help in me.
Upvotes: 3
Views: 105
Reputation: 14408
string= str.replaceAll("\[.*\]", "strToReplace")
to
String s = str.replaceAll("\\[(.*?)\\]","[" + "strToReplace" + "]");
Upvotes: 1
Reputation: 474
String s = str.replaceAll("\[.*\]", "strToReplace")
to
String s = str.replaceAll("\[.*?\\]", "["+"strToReplace"+"]")
Upvotes: 2