def extract_regex(regex, text, encoding='utf-8'):

    if isinstance(regex, six.string_types):
        regex = re.compile(regex, re.UNICODE)

    try:
        strings = [regex.search(text).group('extract')]   # named group
    except:
        strings = regex.findall(text)    # full regex or numbered groups
    strings = flatten(strings)

    if isinstance(text, six.text_type):
        return [replace_entities(s, keep=['lt', 'amp']) for s in strings]
    else:
        return [replace_entities(to_unicode(s, encoding), keep=['lt', 'amp'])
                for s in strings]
Extract a list of unicode strings from the given text/encoding using the following policies:
dataset/ETHPy150Open scrapy/scrapy/scrapy/utils/misc.py/extract_regex