def find_matches(key_mask, text, requirements=None):
        """
        @type key_mask: str
        @type text: str
        """
        mapping = {}

        expected = key_mask.split('/')
        actual = text.split('/')

        for key, value in zip(expected, actual):
            if len(key) >= 3 and (key[0] == '{' and key[-1] == '}'):
                if not requirements:
                    requirements = {}
                key = key[1:-1]
                if key in requirements and not re.match('^' + requirements[key] + '$', value):
                    return None
                mapping[key] = value
            elif key != value:
                return None

        return mapping
def find_matches ( key_mask , text , requirements = None ) : mapping = { } expected = key_mask . split ( '/' ) actual = text . split ( '/' ) for key , value in zip ( expected , actual ) : if len ( key ) >= 3 and ( key [ 0 ] == '{' and key [ - 1 ] == '}' ) : if not requirements : requirements = { } key = key [ 1 : - 1 ] if key in requirements and not re . match ( '^' + requirements [ key ] + '$' , value ) : return None mapping [ key ] = value elif key != value : return None return mapping
@type key_mask: str
        @type text: str