A string will be made up of certain symbols (ax,bx,dx,c,acc for example) and numbers.
ex: ax 5 5 dx 3 acc c ax bx
I want to replace one or all of the symbols (randomly) with another symbol of the same set. ie, replace one of {ax,bx,dx,c,acc} with one of {ax,bx,dx,c,acc}.
replacement example: acc 5 5 dx 3 acc c ax bx or c 5 5 dx 3 acc c ax ax
Is there a way to do this with regexes? In Java? If so, which methods should I use?
I think this is the most clean solution for replacing a certain set of symbols from a string containing a superset of them. appendreplacement is the key to this method. one important caveat: do not include any unescped dollar characters ($) in your elements list. escape them by using ‘\$’ eventually use
.replaceall(‘\$’,’\\$’); on every string before adding it to the list. see also the javadoc in doubt about the $ signs.