For example, if I were to make the keyphrase "ball", then I would need the sentence "He caught the ball because he was playing baseball" to "He caught the XXXX because he was playing baseball". Instead, I'm getting "He caught the XXXX because he was playing baseXXXX". I'm using replaceAll, which is why I'm getting this error, but I was wondering if there is a way for me to check if there's a character that isn't whitespace afterwards, and only replace the word if there is either whitespace or special characters. The reason I'm struggling is because I still want the word to replaced if it is followed by a special character, but not a letter.