How to remove any custom tags from text (strings) using Python

BS4 and other tools allow to remove HTML tags (.decompose(), .get_text() etc.) but there are situations when strings contain some other markup which cannot be filtered out by standard tools. This function in Python allows to set the tag mask which needs to be removed and removes all occurrences.

# The function:
def delete_tags(txt,tags):
    for tag in tags:
        tag_starts = 0
        while tag_starts!=-1:
            tag_starts = txt.find(tag[0])
            tag_ends = txt[tag_starts:].find(tag[1]) + tag_starts
            txt = txt.replace(txt[tag_starts:tag_ends+len(tag[1])],"")
    return txt

#how to use:
#provide list of tuples of tags (begining of a tag, end of a tag) Example:
tags = [("[tagid:","]"),("<http",">"),("<mailto",">"),("{tagid","}")]

#Example input text:
text_with_tags = "This is an example < > Tag2 [tagid:tagvalue] tag3: {tagid:tagvalue} "

text_without_tags = delete_tags(text_with_tags, tags)