replaceAll accepts a regular expression as a parameter.
In regular expressions, you have word boundaries : \b (use \\b in a string literal). This is the best way to match a word, not a part of a word: "\\bword\\b"
But in your case, you cannot use word boundaries because you are not looking for a word ( [69-3] not a word).
I suggest the following:
text=text.replaceAll("(?=\\W+|^)"+Pattern.quote("[69-3]")+"(?=\\W+|$)", ...
The idea is to match the end of a line or something that is not a word. I can not guarantee that this will be the right solution for you: such a template should be customized, knowing the exact full use case.
Please note that if all your keys correspond to a similar pattern, there may be a better solution than repeating iteration through the dictionary, you can use, for example, a pattern, for example "(?=\\W+|^)\\[\\d+\\-\\d+\\](?=\\W+|$)" . "(?=\\W+|^)\\[\\d+\\-\\d+\\](?=\\W+|$)"
source share