当前位置: 首页>>代码示例>>Python>>正文


Python re2.compile方法代码示例

本文整理汇总了Python中re2.compile方法的典型用法代码示例。如果您正苦于以下问题:Python re2.compile方法的具体用法?Python re2.compile怎么用?Python re2.compile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在re2的用法示例。


在下文中一共展示了re2.compile方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: impfuzzy_comp

# 需要导入模块: import re2 [as 别名]
# 或者: from re2 import compile [as 别名]
def impfuzzy_comp(self, list, list_new):    
        ssdeep = re.compile("^[0-9]{1,5}:[0-9a-zA-Z\/\+]+:[0-9a-zA-Z\/\+]+$", re.DOTALL)
        complist = []
        list_len = len(list_new)
        i = 0
        for item_new in list_new:
            i += 1
            if re.search(ssdeep, item_new[2]) and len(item_new[2]) < 150:
                for j in range(i, list_len):
                    if re.search(ssdeep, list_new[j][2]) and len(list_new[j][2]) < 150:
                        complist.append([item_new[0], list_new[j][0], pyimpfuzzy.hash_compare(item_new[2], list_new[j][2])])

        if list:
            for item_new in list_new:
                if re.search(ssdeep, item_new[2]) and len(item_new[2]) < 150:
                    for item in list:
                        if re.search(ssdeep, item[2]) and len(item[2]) < 150:
                            complist.append([item_new[0], item[0], pyimpfuzzy.hash_compare(item_new[2], item[2])])

        return complist 
开发者ID:TheHive-Project,项目名称:Cortex-Analyzers,代码行数:22,代码来源:malwareclustering_api.py

示例2: _combined_regex

# 需要导入模块: import re2 [as 别名]
# 或者: from re2 import compile [as 别名]
def _combined_regex(regexes, flags=re.IGNORECASE, use_re2=False, max_mem=None):
    """
    Return a compiled regex combined (using OR) from a list of ``regexes``.
    If there is nothing to combine, None is returned.

    re2 library (https://github.com/axiak/pyre2) often can match and compile
    large regexes much faster than stdlib re module (10x is not uncommon),
    but there are some gotchas:

    * in case of "DFA out of memory" errors use ``max_mem`` argument
      to increase the amount of memory re2 is allowed to use.
    """
    joined_regexes = "|".join(r for r in regexes if r)
    if not joined_regexes:
        return None

    if use_re2:
        import re2
        return re2.compile(joined_regexes, flags=flags, max_mem=max_mem)
    return re.compile(joined_regexes, flags=flags) 
开发者ID:scrapinghub,项目名称:adblockparser,代码行数:22,代码来源:parser.py

示例3: __post_init__

# 需要导入模块: import re2 [as 别名]
# 或者: from re2 import compile [as 别名]
def __post_init__(self):
        re2.compile(self.pattern)  # raise error if invalid 
开发者ID:CJWorkbench,项目名称:cjworkbench,代码行数:4,代码来源:param_spec.py

示例4: str_to_regex

# 需要导入模块: import re2 [as 别名]
# 或者: from re2 import compile [as 别名]
def str_to_regex(s: str, case_sensitive: bool):
    """
    Convert to regexp, or raise UserVisibleError.
    """
    try:
        # Compile the actual regex, to generate the actual error message.
        r = re2.compile(s)
    except re2.error as err:
        # Handle https://github.com/facebook/pyre2/pull/16
        # Sometimes err.msg is an integer and err.pattern is the actual error
        # message.
        #
        # Nix this when upstream is fixed.
        if isinstance(err.msg, int):
            msg = err.pattern
        else:
            msg = str(err)
        raise UserVisibleError("Regex parse error: %s" % msg)

    if not case_sensitive:
        # case-insensitive: compile _again_ (fb-re2 doesn't support
        # case-insensitive flag; we want the error message to apply to the
        # original pattern because any valid original pattern should be valid
        # here -- otherwise it's a dev error.)
        r = re2.compile(f"(?i:{s})")

    return r 
开发者ID:CJWorkbench,项目名称:cjworkbench,代码行数:29,代码来源:filter.py

示例5: _url_matches

# 需要导入模块: import re2 [as 别名]
# 或者: from re2 import compile [as 别名]
def _url_matches(self, url):
        if self.regex_re is None:
            self.regex_re = re.compile(self.regex)
        return bool(self.regex_re.search(url)) 
开发者ID:scrapinghub,项目名称:adblockparser,代码行数:6,代码来源:parser.py

示例6: __init__

# 需要导入模块: import re2 [as 别名]
# 或者: from re2 import compile [as 别名]
def __init__(self, option):
        assert isinstance(option, list)
        assert len(option) == 1

        value = option[0]
        assert value[0] == '"' and value[-1] == '"'

        self.regex_string = value[1:-1]
        assert '"' not in self.regex_string, "embeded quotes not handled"
        self.regex = re.compile(self.regex_string) 
开发者ID:mechaphish,项目名称:pov_fuzzing,代码行数:12,代码来源:rule_options.py


注:本文中的re2.compile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。