cltk/cltk · query.py
python logo
def _regex_span(_regex, _str, case_insensitive=True):
    """Return all matches in an input string.
    :rtype : regex.match.span
    :param _regex: A regular expression pattern.
    :param _str: Text on which to run the pattern.
    """
    if case_insensitive:
        flags = regex.IGNORECASE | regex.FULLCASE | regex.VERSION1
    else:
        flags = regex.VERSION1
    comp = regex.compile(_regex, flags=flags)
    matches = comp.finditer(_str)
    for match in matches:
        yield match
Similar code snippets
1.
maximkulkin/hypothesis-regex · hypothesis_regex.py
Match rating: 61.18% · 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)
2.
lotrekagency/djlotrek · djlotrek_filters.py
Match rating: 60.33% · See similar code snippets
python logo
def regex_match(value, regex):
    pattern = re.compile(regex)
    if pattern.match(value):
        return True
3.
ouroboroscoding/format-oc-python · __init__.py
Match rating: 59.0% · See similar code snippets
python logo
def regex(self, regex = None):
		"""Regex

		Sets or gets the regular expression used to validate the Node

		Arguments:
			regex {str} -- A standard regular expression string

		Raises:
			ValueError

		Returns:
			None | str
		"""

		# If regex was not set, this is a getter
		if regex is None:
			return self._regex

		# If the type is not a string
		if self._type != 'string':
			sys.stderr.write('can not set __regex__ for %s' % self._type)
			return

		# If it's not a valid string or regex
		if not isinstance(regex, (basestring, _REGEX_TYPE)):
			raise ValueError('__regex__')

		# Store the regex
		self._regex = regex
4.
petermelias/valhalla · strings.py
Match rating: 58.84% · 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.
NiklasRosenstein-Python/nr-deprecated · strex.py
Match rating: 58.7% · 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
6.
shanbay/peeweext · validation.py
Match rating: 57.91% · See similar code snippets
python logo
def __init__(self, regex):
        self._regex = regex
        self._compiled_regex = re.compile(regex)
7.
atsuoishimoto/tse · main.py
Match rating: 57.88% · 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)
8.
kaste/mockito-python · matchers.py
Match rating: 57.46% · See similar code snippets
python logo
def __repr__(self):
        if self.regex.flags:
            return "<Matches: %s flags=%d>" % (self.regex.pattern,
                                               self.regex.flags)
        else:
            return "<Matches: %s>" % self.regex.pattern
9.
rossant/ipymd · prompt.py
Match rating: 57.34% · See similar code snippets
python logo
def _starts_with_regex(line, regex):
    """Return whether a line starts with a regex or not."""
    if not regex.startswith('^'):
        regex = '^' + regex
    reg = re.compile(regex)
    return reg.match(line)
10.
jpscaletti/solution · patterns.py
Match rating: 57.32% · 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