to remove all last possible patterns ( all exclamation marks) from the end of string, the code is following: but if double exclamation marks, it does not function, where is the mistake in my code? def remove(s): import re for x in s: return re.sub(r'!#x27;, '', s)
Thanks rodwynnejones! rstrip() method worked!
I think you have to add + in the pattern or * instead of $ to remove occurrences of exclamation mark.
Give example input and expected output. You code looks like you iterating through the characters of a string but your returning after the first iteration. Do you need to use "re"?....if not...have a look at string rstrip() method.
Thanks for the answer! But: with * instead of $, it will remove all exclamation marks, for example, if they are at the beginning. But I need only from the end of the string. with add, does no working.
Input :[ 'Python !!'] Output : [ 'Python']
If you still want to use regex use this pattern: r"!+quot; It means "one or more exclamation marks at the end of the string" and should work.
what if : input : „!pyth!on!!!“ output: „python!!!“ removing with regex first and second , but NOT the end?
Meka Can you share your edited code? It's working as expected for me: import re input = "„!pyth!on!!!" print(re.sub(r"!+quot;,"",input))
Try with the dot with ? Like this r'!.?#x27;