sourcedstring.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:gateplugin-python 作者: GateNLP 项目源码 文件源码
def patch_re_module():
        """
        Modify the standard ``re`` module by installing new versions of
        the functions ``re.compile``, ``re.sub``, and ``re.subn``,
        causing regular expression substitutions to return
        ``SourcedStrings`` when called with ``SourcedStrings``
        arguments.

        Use this function only if necessary: it potentially affects
        all Python modules that use regular expressions!
        """
        def new_re_sub(pattern, repl, string, count=0):
            return re.compile(pattern).sub(repl, string, count)
        def new_re_subn(pattern, repl, string, count=0):
            return re.compile(pattern).subn(repl, string, count)
        re.compile = SourcedStringRegexp
        re.sub = new_re_sub
        re.subn = new_re_subn
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号