import re


def substitute_pattern_with_char(s, pattern, repl_char='x'):
    """
    This is a little different than re.sub(). It replaces all the characters
    that match the pattern with an equal number of `repl_char` characters.

    The resulting string should be the same length as the starting string.

    >>> substitute_pattern_with_char(s='Hi there', pattern=r'[a-z]+', repl_char='x')
    'Hx xxxxx'

    >>> substitute_pattern_with_char(s='With 42 cats', pattern=r'[\d]+', repl_char='x')
    'With xx cats'

    >>> substitute_pattern_with_char(s='With 42 cats and 12 dogs', pattern=r'[\d]+', repl_char='x')
    'With xx cats and xx dogs'

    >>> substitute_pattern_with_char(s='With 42 cats and 12 dogs', pattern=r'[\d]+\s+(cat[s]?|bird[s]?)', repl_char='x')
    'With xxxxxxx and 12 dogs'

    """
    for mo in re.finditer(pattern=pattern, string=s):
        m = mo.group(0)
        s = s.replace(m, ''.join([repl_char for i in range(0, len(m))]))

    return s