atsuoishimoto/tse · main.py
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)
Similar code snippets
1.
cos-archives/modular-odm · __init__.py
Match rating: 73.65% · 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)
2.
knipknap/exscript · cast.py
Match rating: 70.23% · See similar code snippets
python logo
def to_regex(regex, flags=0):
    """
    Given a string, this function returns a new re.RegexObject.
    Given a re.RegexObject, this function just returns the same object.

    :type  regex: string|re.RegexObject
    :param regex: A regex or a re.RegexObject
    :type  flags: int
    :param flags: See Python's re.compile().
    :rtype:  re.RegexObject
    :return: The Python regex object.
    """
    if regex is None:
        raise TypeError('None can not be cast to re.RegexObject')
    if hasattr(regex, 'match'):
        return regex
    return re.compile(regex, flags)
3.
marshmallow-code/marshmallow · validate.py
Match rating: 69.65% · 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
4.
petermelias/valhalla · strings.py
Match rating: 68.79% · 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.
jpscaletti/solution · patterns.py
Match rating: 68.48% · 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
6.
maximkulkin/hypothesis-regex · hypothesis_regex.py
Match rating: 68.22% · See similar code snippets
python logo
def regex(regex):
    """Return strategy that generates strings that match given regex.

    Regex can be either a string or compiled regex (through `re.compile()`).

    You can use regex flags (such as `re.IGNORECASE`, `re.DOTALL` or `re.UNICODE`)
    to control generation. Flags can be passed either in compiled regex (specify
    flags in call to `re.compile()`) or inside pattern with (?iLmsux) group.

    Some tricky regular expressions are partly supported or not supported at all.
    "^" and "$" do not affect generation. Positive lookahead/lookbehind groups
    are considered normal groups. Negative lookahead/lookbehind groups do not do
    anything. Ternary regex groups ('(?(name)yes-pattern|no-pattern)') are not
    supported at all.
    """
    if not hasattr(regex, 'pattern'):
        regex = re.compile(regex)

    pattern = regex.pattern
    flags = regex.flags

    codes = sre.parse(pattern)

    return _strategy(codes, Context(flags=flags)).filter(regex.match)
7.
NiklasRosenstein-Python/nr-deprecated · strex.py
Match rating: 67.89% · 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
8.
mcs07/ChemDataExtractor · selector.py
Match rating: 67.61% · See similar code snippets
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))
9.
refnode/liquid · strscan.py
Match rating: 66.81% · 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
10.
ianmiell/shutit · shutit_util.py
Match rating: 66.39% · See similar code snippets
python logo
def check_regexp(regex):
	if regex is None:
		# Is this ok?
		return True
	try:
		re.compile(regex)
		return True
	except re.error:
		return False