This is for a game in which the user can enter a value such as “Iced tea ..” I would like to manipulate the string to return “Iced tea” without any punctuation marks.
Look for the most elegant / simplest solution for python.
I tried
def last_character(word): if word.endswith('.' or ','): word = word[:-1] return word
which works if there is only one punctuation mark at the end. But this is not all-encompassing.
Java solution found :
String resultString = subjectString.replaceAll("([az]+)[?:!.,;]*", "$1");
source share