RudolfCardinal/pythonlib · sql_grammar.py
python logo
def make_pyparsing_regex(regex_str: str,
                         caseless: bool = False,
                         name: str = None) -> Regex:
    flags = re.IGNORECASE if caseless else 0
    result = Regex(regex_str, flags=flags)
    if name:
        result.setName(name)
    return result
Similar code snippets
1.
RudolfCardinal/pythonlib · sql_grammar.py
Match rating: 67.23% · See similar code snippets
python logo
def make_words_regex(words_as_string_or_list: Union[str, List[str]],
                     caseless: bool = False,
                     name: str = None,
                     debug: bool = False) -> Regex:
    regex_str = multiple_words_regex_element(words_as_string_or_list)
    if debug:
        log.debug(regex_str)
    return make_pyparsing_regex(regex_str, caseless=caseless, name=name)
2.
RudolfCardinal/pythonlib · sql_grammar.py
Match rating: 66.05% · See similar code snippets
python logo
def sql_keyword(word: str) -> Regex:
    regex_str = word_regex_element(word)
    return make_pyparsing_regex(regex_str, caseless=True, name=word)
3.
closeio/cleancat · base.py
Match rating: 65.06% · See similar code snippets
python logo
def __init__(self, regex=None, regex_flags=None, regex_message=None,
                 **kwargs):
        super(Regex, self).__init__(**kwargs)
        if regex is not None:
            self.regex = regex
        if regex_flags is not None:
            self.regex_flags = regex_flags
        if regex_message is not None:
            self.regex_message = regex_message
4.
jkehler/unshortenit · module.py
Match rating: 64.09% · See similar code snippets
python logo
def _build_domain_regex(self):
        regex_str = r'^(' + r'|'.join(self.domains) + r')$'
        regex_str = re.sub(r'\.', '\.', regex_str)
        self._domain_regex = re.compile(regex_str)
5.
MycroftAI/adapt · engine.py
Match rating: 62.96% · See similar code snippets
python logo
def register_regex_entity(self, regex_str):
        """
        A regular expression making use of python named group expressions.

        Example: (?P<Artist>.*)

        regex_str(str): a string representing a regular expression as defined above
        """
        if regex_str and regex_str not in self._regex_strings:
            self._regex_strings.add(regex_str)
            self.regular_expressions_entities.append(re.compile(regex_str, re.IGNORECASE))
6.
riffm/mint · mint.py
Match rating: 62.41% · See similar code snippets
python logo
def __init__(self, token, value=None, regex_str=None):
        assert value or regex_str, 'Provide token text value or regex'
        self.token = intern(token)
        if regex_str is not None:
            self.regex = re.compile(regex_str, re.U)
        else:
            self.regex = re.compile(r'%s' % re.escape(value), re.U)
7.
thautwarm/RBNF · _literal_matcher.py
Match rating: 62.24% · See similar code snippets
python logo
def make_regex_matcher(regex_template: str):
    regex = re.compile(regex_template)

    def match(token: Tokenizer):
        return regex.match(token.value)

    match.raw = (ConstStrPool.cast_to_const("auto_regex"), regex_template)

    return match
8.
webrecorder/pywb · regex_rewriters.py
Match rating: 62.02% · See similar code snippets
python logo
def compile_rules(rules):
        # Build regexstr, concatenating regex list
        regex_str = '|'.join(['(' + rx + ')' for rx, op, count in rules])

        # ensure it's not middle of a word, wrap in non-capture group
        regex_str = '(?<!\w)(?:' + regex_str + ')'

        return re.compile(regex_str, re.M)
9.
Neurita/boyle · strings.py
Match rating: 61.44% · See similar code snippets
python logo
def is_regex(string):
    """
    TODO: improve this!

    Returns True if the given string is considered a regular expression,
    False otherwise.
    It will be considered a regex if starts with a non alphabetic character
    and then correctly compiled by re.compile

    :param string: str

    """
    is_regex = False
    regex_chars = ['\\', '(', '+', '^', '$']
    for c in regex_chars:
        if string.find(c) > -1:
            return is_valid_regex(string)
    return is_regex
10.
Neurita/boyle · strings.py
Match rating: 61.19% · See similar code snippets
python logo
def is_fnmatch_regex(string):
    """
    Returns True if the given string is considered a fnmatch
    regular expression, False otherwise.
    It will look for

    :param string: str

    """
    is_regex = False
    regex_chars = ['!', '*', '$']
    for c in regex_chars:
        if string.find(c) > -1:
            return True
    return is_regex