(regex)
return dict(result)
Find ecodes matching a regex and return a mapping of event type to event codes.

    Example
    -------
    >>> find_ecodes_by_regex(r'(ABS|KEY)_BR(AKE|EAK)')
    {1: [411], 3: [10]}
    >>> res = find_ecodes_by_regex(r'(ABS|KEY)_BR(AKE|EAK)')
    >>> resolve_ecodes_dict(res)
    {
        ('EV_KEY', 1): [('KEY_BREAK', 411)],
        ('EV_ABS', 3): [('ABS_BRAKE', 10)]
    }
Find ecodes matching a regex and return a mapping of event type to event codes.
Find ecodes matching a regex and return a mapping of event type to event codes .
def find_ecodes_by_regex(regex):
    '''
    Find ecodes matching a regex and return a mapping of event type to event codes.

    Example
    -------
    >>> find_ecodes_by_regex(r'(ABS|KEY)_BR(AKE|EAK)')
    {1: [411], 3: [10]}
    >>> res = find_ecodes_by_regex(r'(ABS|KEY)_BR(AKE|EAK)')
    >>> resolve_ecodes_dict(res)
    {
        ('EV_KEY', 1): [('KEY_BREAK', 411)],
        ('EV_ABS', 3): [('ABS_BRAKE', 10)]
    }
    '''

    regex = regex if isinstance(regex, re.Pattern) else re.compile(regex)
    result = collections.defaultdict(list)

    for type_code, codes in ecodes.bytype.items():
        for code, names in codes.items():
            names = (names,) if isinstance(names, str) else names
            for name in names:
                if regex.match(name):
                    result[type_code].append(code)
                    break

    return dict(result)
def find_ecodes_by_regex ( regex ) : regex = regex if isinstance ( regex , re . Pattern ) else re . compile ( regex ) result = collections . defaultdict ( list ) for type_code , codes in ecodes . bytype . items ( ) : for code , names in codes . items ( ) : names = ( names , ) if isinstance ( names , str ) else names for name in names : if regex . match ( name ) : result [ type_code ] . append ( code ) break return dict ( result )