def mask_characters(expression, search_text, target_text, mask_char):
    """Mask characters found by a regular expression with mask character. Mask characters will equal length of masked
    string.
    A different target text to search text may be used, but the developer must ensure that they are compatible.
    This feature may be used to handle combinations of N mask_char(s) differently

    :param expression: regex expression
    :param search_text: text to search for matches
    :param target_text: text to apply mask to
    :param mask_char: character to replace masked characters
    """
    matches = []
    pos = 0
    masked_text = ''
    for match in expression.finditer(search_text):
        matches.append(match)
        masked_text += target_text[pos:match.start()] + mask_char * (match.
            end() - match.start())
        pos = match.end()
    masked_text += target_text[pos:]
    return masked_text, matches
