import re


def normalize_txt(text,patterns): 
    """ Apply a list of subtring replaces over the text. Usefull for normalize
    some text (number of linebreaks between parragraphs, case of the first letter, split or
    join punctuation marks, etc)

    Parameters
    ----------
    doc : str
        Text string to be cleaned.

    patterns : List[Tuple[Pattern[str],Pattern[str]]]
        A list of tuples of regex patterns to be replaced, the first member is 
        the pattern to find and the second the replace pattern.
        
        Note: Take care with the orden of the list of patterns!!!!.
        
        Example of patterns: 
            
            1) Replace <<number:number>> to nothing:
            
            ori_pat1 = (r"\d+\:\d+\ ")
            rep_to_pat1 =  (r"")
            
            2) Replace more than 2 linebreaks with only 2 linebreaks:
            
            ori_pat2 = (r"\n{2,}")
            rep_to_pat2 =  ("\n\n")         
            
            
    Returns
    -------
    string
       New string without the text that matches whit patterns.

    """
    cleaned = []
    clean_text = text
    for pattern in patterns:
        #print("----->>> Patte:",pattern)
        for match in re.finditer(pattern[0], text):
            cleaned.append([match.span(), match.group(), pattern[1]])
            clean_text = re.sub(pattern[0], pattern[1], clean_text)
    return clean_text, cleaned