def _replace_match(text, match, replacement):
    """Expands a regexp match in the text with its replacement.

    Args:
        text: str.  The text in which to perform the replacement.
        match: re.MatchObject.  A match object that applies to "text".
        replacement: str.  The string to replace the match with.

    Returns:
        (str, int).  The text with the substitution performed and the first
        position in the text after the replacement that was done.
    """
    new_text = text[:match.start()] + replacement + text[match.end():]
    new_start_pos = match.start() + len(replacement)
    return new_text, new_start_pos