I currently have a line similar to the following:
str = 'abcHello Wor=A9ld'
What I want to do is find "abc" and "= A9" and replace these mapped groups with an empty string, so my last line is "Hello World".
I am currently using this regex that correctly finds the groups that I want to replace:
r'^(abc).*?(=[A-Z0-9]+)'
I tried replacing these groups using the following code:
clean_str = re.sub(r'^(abc).*?(=[A-Z0-9]+)', '', str)
Using the above code led to:
print(clean_str)
>>> 'ld'
My question is: how can I use re.sub to replace these groups with an empty string and get my "Hello World"?
source
share