Simplified replaceInText() method for Java