I'm not sure how much I understand your questions. If you can articulate it better, I think that simply replacing the regex may be all you need.
String r = s.replaceAll(REGEX, "X");
REGEX depends on what you need:
"\\*|#|~" : matches only '*', "#', and '~' "[^\\d\\w]" : matches anything that is neither a digit nor a word character "\\[.\\]" : matches '[' followed by ANY character followed by ']' "(?<=\\[).(?=\\])" : matches only the character surrounded by '[' and ']'
source share