import six
import re


def keys_by_pattern_dict(in_dict, patterns, matchs=None):
    """ Recursive dictionary lookup by regex pattern.

        Args:
            in_dict (dict): Input dict.
            patterns (list): Lookup regex pattern list.
            matchs (list): Match accumulator (recursive call only).

        Returns:
            List of Value for each key found in ``in_dict``.

        >>> sorted(
        ...  keys_by_pattern_dict(
        ...   {'key1': {'mykey': 1}, 'key2': {'mykey': 2}, 'mykey': 3},
        ...   [r'^[A-Za-z]*$']
        ...  )
        ... )
        [1, 2, 3]

    """
    matchs = [] if matchs is None else matchs

    if isinstance(in_dict, dict):
        for k, v in six.iteritems(in_dict):
            if any([re.search(p, k) for p in patterns]):
                matchs.append(in_dict[k])
            keys_by_pattern_dict(v, patterns, matchs)
    if isinstance(in_dict, list):
        [keys_by_pattern_dict(item, patterns, matchs) for item in in_dict]

    return matchs