fix replace bug

previously used replaceAll which causes
index out of bounds exception