Regex to change multiple lines

Termoregolato waste at is.invalid
Thu Sep 3 10:10:58 EDT 2020


Hi. I've on file, containing multiple lines, and I need to change every 
occurrence of a sequence between two chars, in this case "%%".

-- original
This is the %%text that i must modify%%, on a line, %%but also
on the others%% that are following

I need to change to

-- desidered
This is the <del>text that i must modify</del>, on a line, <del>but also
on the others</del> that are following

I've tryed with this small code

rebarredtext = r'~~([^>]*)~~'
text = mycontent
   for line in re.findall(rebarredtext, text):
     text = text.replace("~~" + line + "~~", "<del>" + line + "</del>")


but it changes only the biggest occurrence: how can I do to change all 
occurrences? I'm really a regex newbie, TIA

-- test
This is the <del>text that i must modify%%, on a line, %%but also
on the others</del> that are following


More information about the Python-list mailing list