import re


def extract_migration(script, name):
    """Extract given (forward, reverse) migration from script"""
    functions_regex = (
        r'.*(?P<forward>function forward.+{.+})'
        r'.*(?P<reverse>function reverse.+{.+}).*'
    )
    matches = re.fullmatch(functions_regex, script, re.DOTALL)
    if matches and name in matches.groupdict():
        return matches.group(name)