mcs07/ChemDataExtractor · selector.py
python logo
def re(self, regex):
        if isinstance(regex, six.string_types):
            regex = re.compile(regex, re.U)
        text = self.extract()
        return flatten(regex.findall(text))
Similar code snippets
1.
atsuoishimoto/tse · main.py
Match rating: 67.61% · See similar code snippets
python logo
def build_re(self, regex):
        if not regex:
            regex = '.*'
        flags = re.I if self.ignore_case else 0
        return re.compile(regex, flags)
2.
AnalogJ/lexicon · hetzner.py
Match rating: 67.06% · See similar code snippets
python logo
def _extract_domain_id(string, regex):
        """
        Extracts domain ID from given string and returns the domain ID.
        """
        regex = re.compile(regex)
        match = regex.search(string)
        if not match:
            return False
        return str(match.group(1))
3.
jpscaletti/solution · patterns.py
Match rating: 66.74% · See similar code snippets
python logo
def __init__(self, regex, message=None, flags=re.IGNORECASE):
        if isinstance(regex, string_types):
            regex = re.compile(regex, flags)
        self.regex = regex
        if message is not None:
            self.message = message
4.
petermelias/valhalla · strings.py
Match rating: 66.47% · See similar code snippets
python logo
def regex(regex, case=False, _value=None, *args, **kwargs):
    if kwargs.get('case'):
        regex = re.compile(regex)
    else:
        regex = re.compile(regex, re.IGNORECASE)

    if not regex.match(_value):
        raise ValidationError('The _value must match the regex %s' % regex)

    return _value
5.
refnode/liquid · strscan.py
Match rating: 66.36% · See similar code snippets
python logo
def get_regex(regex):
    """
    Ensure we have a compiled regular expression object.

        >>> import re
        >>> get_regex('string') # doctest: +ELLIPSIS
        <_sre.SRE_Pattern object at 0x...>
        >>> pattern = re.compile(r'string')
        >>> get_regex(pattern) is pattern
        True
        >>> get_regex(3) # doctest: +ELLIPSIS
        Traceback (most recent call last):
        ...
        TypeError: Invalid regex type: 3
    """
    if isinstance(regex, basestring):
        return re.compile(regex)
    elif not isinstance(regex, re._pattern_type):
        raise TypeError("Invalid regex type: %r" % (regex,))
    return regex
6.
NiklasRosenstein-Python/nr-deprecated · strex.py
Match rating: 65.0% · See similar code snippets
python logo
def __init__(self, name, regex, flags=0, skip=False):
    super(Regex, self).__init__(name, skip)
    if isinstance(regex, string_types):
      regex = re.compile(regex, flags)
    self.regex = regex
7.
rougeth/bottery · handlers.py
Match rating: 64.79% · See similar code snippets
python logo
def match(self, message):
        if not self.regex:
            self.regex = re.compile(self.pattern)

        if self.regex.match(message.text):
            return True
        return False
8.
usc-isi-i2/etk · Validation.py
Match rating: 64.33% · See similar code snippets
python logo
def user_regex(self, field_extraction, regex):
        #print "in user_regex"
        extract = field_extraction['extract']
        regex = re.compile(regex)
        # apply pattern
        if regex.match(extract):
            # print "matched:", extract
            return True
        else:
            return False
9.
marshmallow-code/marshmallow · validate.py
Match rating: 64.08% · See similar code snippets
python logo
def __init__(self, regex, flags=0, error=None):
        self.regex = re.compile(regex, flags) if isinstance(regex, basestring) else regex
        self.error = error or self.default_message
10.
cos-archives/modular-odm · __init__.py
Match rating: 63.82% · See similar code snippets
python logo
def __init__(self, regex=None, flags=0):

        if regex is not None:
            self.regex = re.compile(regex, flags=flags)