import re
import inspect


def get_source(match: re.Match) -> str:
    """Extract source code lines of a matched object and prepare them
    to being injected into .ipynb code cell."""
    match_object = eval(match.group()[9:-1])
    source_lines = inspect.getsourcelines(match_object)[0]
    new_lines = [line.rstrip() for line in source_lines]

    escape_symbols_re = re.compile(r'([\\"])')

    new_lines = [
        r'"{0}\n",'.format(escape_symbols_re.sub(r'\\\1', line))
        for line
        in new_lines
    ]

    # delete the redundant `"` prefix of the first line
    new_lines[0] = new_lines[0][1:]
    # delete the redundant `\n",` suffix of the last line
    new_lines[-1] = new_lines[-1][:-4]

    return ''.join(new_lines)