import re


def strip_tw_links(usfm, links=None):
    """
    Removes tW links from a usfm string.
    This does not remove milestone markers.

    :param usfm:
    :param links: only remove these links. If left None all links will be removed. Milestones are always removed.
    :return:
    """
    updated_usfm=usfm
    # remove links
    if links:
        for link in links:
            updated_usfm = re.sub(r'x-tw="' + re.escape(link) + '"\s*', '', updated_usfm)
    else:
        updated_usfm = re.sub(r'x-tw="([^"]*)"\s*', '', updated_usfm)
    return updated_usfm