I need to replace a string:
"abc.T.T.AT.T"
to a string with all single T
to be replaced by TOT
like
"abc.TOT.TOT.AT.TOT"
strings.replaceAll
not working for this.
look around will solve your problem:
s.replaceAll("(?<=\\.|^)T(?=\\.|$)", "TOT");
if you do:
String s = "T.T.T.AT.T.fT.T.T";
System.out.println(s.replaceAll("(?<=\\.|^)T(?=\\.|$)", "TOT"));
output would be:
TOT.TOT.TOT.AT.TOT.fT.TOT.TOT
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With