string.replaceAll to replace occurrences
java, regex, string
Solution
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
Problem
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.