I have an input string which looks something like this.
String str="abc + abcd * abcde"
I wish to replace
abc with "xyz".
When I try replace function of string it replaces all the occurences of abc.
I should have the final string as
String str="xyz + abcd * abcde"
It is not necessary that "abc" will be first word in String.
I need to replace only that word which contains "abc" and not the one which contains "abcd". If I use "replace", it will replace all occurences of abc which is not required.
"abc" will have operator after abc. Something like this "abc+abcd+abcde"
Is there any elegant solution to this problem ?
abcis from the other occurrences...str.replaceAll("\\b(abc)\\b", "xyz")