I need a regex in Python that will remove the last word from a string if it contains a certain character, in this case ‘#’, and in other appearances of that character ‘#’, only the character is removed, not the word.
So the string:
What a #great day #happy
would become:
What a great day
so far I have tried
entry = re.sub('(?<=#)\w+','',entry)
but this removes all words containing ‘#’.
yields