Should be str.replaceAll instead of str.replace otherwise just the first occurrence will be processed.