import re | |
def clean_sentence(sentence): | |
# Remove "!", "?", ".", "(", ")" from the sentence | |
sentence = re.sub(r"[!.?()]", "", sentence) | |
# Replace " , " with an empty space | |
sentence = re.sub(r" , ", " ", sentence) | |
# Remove any trailing commas | |
sentence = re.sub(r"^,|,$", "", sentence) | |
# Strip spaces | |
sentence = sentence.strip() | |
# Remove any usernames | |
words = sentence.split(", ") | |
result = [] | |
for word in words: | |
word = word.strip() | |
if word == 'v': | |
result.append(word) | |
continue | |
if len(word) < 2: | |
continue | |
if any(char.isdigit() for char in word) and word not in ["1girl", "1boy", "1koma", "1other"]: | |
continue | |
result.append(word) | |
return ", ".join(result) |