Returns a compiled regex for this drug.
432980
def regex(self) -> Pattern:
        
        if self._regex is None:
            self._regex = re.compile(self.regex_text,
                                     re.IGNORECASE | re.DOTALL)
        return self._regex
1351871
def _prepare_pattern(self, pattern):
        
        regex, _, rest = pattern.partition('\\;')
        try:
            return re.compile(regex, re.I)
        except re.error as e:
            warnings.warn(
                "Caught '{error}' compiling regex: {regex}"
                .format(error=e, regex=regex)
            )
            # regex that never matches:
            # http://stackoverflow.com/a/1845097/413622
            return re.compile(r'(?!x)x')
704658
def _regex_from_encoded_pattern(s):
    """'
    """
    if s.startswith('/') and s.rfind('/') != 0:
        # Parse it: /PATTERN/FLAGS
        idx = s.rfind('/')
        pattern, flags_str = s[1:idx], s[idx+1:]
        flag_from_char = {
            "i": re.IGNORECASE,
            "l": re.LOCALE,
            "s": re.DOTALL,
            "m": re.MULTILINE,
            "u": re.UNICODE,
        }
        flags = 0
        for char in flags_str:
            try:
                flags |= flag_from_char[char]
            except KeyError:
                raise ValueError("unsupported regex flag: '%s' in '%s' "
                                 "(must be one of '%s')"
                                 % (char, s, ''.join(list(flag_from_char.keys()))))
        return re.compile(s[1:idx], flags)
    else: # not an encoded regex
        return re.compile(re.escape(s))
265810
def result(self):
         
        field = re.sub(REGEX_CLEANER, '', self.field_name)

        if self.alias:
            alias = re.sub(REGEX_CLEANER, '', self.alias)
            return "%s AS %s" % (field, alias)
        else:
            return field
637896
def re_filter(text, regexps):
    """"""
    if not regexps:
        return text

    matched_text = []
    compiled_regexps = [re.compile(x) for x in regexps]
    for line in text:
        if line in matched_text:
            continue

        for regexp in compiled_regexps:
            found = regexp.search(line)
            if found and found.group():
                matched_text.append(line)

    return matched_text or text
1271809
def _match(self, regex):
        """"""
        cregex = re.compile(regex)
        for line in self.content.splitlines():
            match = cregex.match(line)
            if match:
                return match
        raise Exception('No "{0}" line in {1}.cpp'.format(
            regex_to_error_msg(regex),
            self.name
        ))
1191376
def _get_regex_pattern(label):
    
    parts = _split_by_punctuation.split(label)

    for index, part in enumerate(parts):
        if index % 2 == 0:
            # Word
            if not parts[index].isdigit() and len(parts[index]) > 1:
                parts[index] = _convert_word(parts[index])
        else:
            # Punctuation
            if not parts[index + 1]:
                # The separator is not followed by another word. Treat
                # it as a symbol.
                parts[index] = _convert_punctuation(
                    parts[index],
                    current_app.config["CLASSIFIER_SYMBOLS"]
                )
            else:
                parts[index] = _convert_punctuation(
                    parts[index],
                    current_app.config["CLASSIFIER_SEPARATORS"]
                )

    return "".join(parts)
1250686
def to_python(self, value):
        
        if isinstance(value, type(re.compile(''))):
            return value
        else:
            if value is None and self.null:
                return None
            else:
                try:
                    return self.get_compiled_regex(value)
                except:
                    raise ValidationError('Invalid regex {0}'.format(value))
1055211
def _compileRegExp(string, insensitive, minimal):
        
        flags = 0
        if insensitive:
            flags = re.IGNORECASE

        string = string.replace('[_[:alnum:]]', '[\\w\\d]') # ad-hoc fix for C++ parser
        string = string.replace('[:digit:]', '\\d')
        string = string.replace('[:blank:]', '\\s')

        try:
            return re.compile(string, flags)
        except (re.error, AssertionError) as ex:
            _logger.warning("Invalid pattern '%s': %s", string, str(ex))
            return None
1016509
def _compile(self, p):
        
        if self._is_value_filter(p) and p[0] == '=~':
            try:
                p[2] = re.compile(p[2])
            except:  # Python doesn't document exactly what exceptions re.compile throws
                raise ValueError('Bad regex - {0}'.format(p[2]))
        elif self._is_operator(p):
            for operator_or_filter in (p[1] if p[0] != '!' else [p[1]]):
                self._compile(operator_or_filter)
342942
def _namematcher(regex):
    """"""

    matcher = re_compile(regex)

    def match(target):
        target_name = getattr(target, '__name__', '')
        result = matcher.match(target_name)
        return result

    return match
538124
def decamel(string):
    "
    regex = re.compile(r'(\B[A-Z][a-z]*)')
    return regex.sub(r' \1', string)
636788
def match(self, regexp, flags=None):
        """"""

        try:
            reg = _regexp_cache[(regexp, flags)]
        except KeyError:
            if flags:
                reg = re.compile(regexp, flags)
            else:
                reg = re.compile(regexp)
            _regexp_cache[(regexp, flags)] = reg

        return self.match_reg(reg)
989699
def regex_opt(strings, prefix='', suffix=''):
    
    strings = sorted(strings)
    return prefix + regex_opt_inner(strings, '(') + suffix
697553
def regex(self, regex = None):
		

		# 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
1188596
def regxy(pattern, response, supress_regex, custom):
    """"""
    try:
        matches = re.findall(r'%s' % pattern, response)
        for match in matches:
            verb('Custom regex', match)
            custom.add(match)
    except:
        supress_regex = True
1242413
def compile_regex(self, fmt, query):
        """"""
        return re.compile(fmt.format(
            query.pattern.replace('.', '\.').replace('*', '[^\.]*').replace(
                '{', '(').replace(',', '|').replace('}', ')')
        ))