Simple Java regex not working
问题 I have this regex which is supposed to remove sentence delimiters( . and ? ): sentence = sentence.replaceAll("\\.|\\?$",""); It works fine it converts "I am Java developer." to "I am Java developer" "Am I a Java developer?" to "Am I a Java developer" But after deployment we found that it also replaces any other dots in the sentence as "Hi.Am I a Java developer?" becomes "HiAm I a Java developer" Why is this happening? 回答1: The pipe ( | ) has the lowest precedence of all operators. So your