How to replace punctations at the end and beginning of a string : How can I remove all punctuations except ' in the first character and last character of a string in java. I have tried using regex with replaceFirst() but didn't succeed.