Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace Character inside brackets

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.

like image 671
JayR Avatar asked Dec 02 '25 02:12

JayR


1 Answers

String s = str.replaceAll("\[.*\]", "strToReplace")

to

String s = str.replaceAll("\[.*?\\]", "["+"strToReplace"+"]")
like image 190
rubberdont Avatar answered Dec 03 '25 20:12

rubberdont



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!