It’s for a game in which the user can input a value like “Iced tea..”
I would like to manipulate the string to return “Iced tea” without the trailing punctuation marks.
Looking for most elegant / simplest python solution.
Tried
def last_character(word):
if word.endswith('.' or ','):
word = word[:-1]
return word
which works if there’s only one punctuation mark at the end. But it’s not all-encompassing.
Found a Java solution:
String resultString = subjectString.replaceAll("([a-z]+)[?:!.,;]*", "$1");
1 Answer