import re


def _key_in_set(key, keys, keys_regex=False):
    """Determine whether ``key`` is among ``keys``, with or without regex
    """
    if keys_regex:
        return any(re.compile(k).match(key) for k in keys)
    else:
        return key in keys