I have a large string in which I have the characters available in the following patterns -
A&B A & B A& B A &B A&B A & B A& B A &B
I want to replace all occurrences and the character with & When replacing this, I must also make sure that I do not mistakenly convert & in & . How do I do this in terms of performance? Am I using regex? If yes, please, can you help me choose the right regular expression to do the above?
I have tried so far without joy:
data = data.replace(" & ", "&"); // doesn't replace all & data = data.replace("&", "&"); // replaces all &, so & becomes &
java string regex replace ampersand
sribasu
source share