Type of compiled regex object in python

后端 未结 10 1089
一个人的身影
一个人的身影 2020-11-30 07:14

What is the type of the compiled regular expression in python?

In particular, I want to evaluate

isinstance(re.compile(\'\'), ???)

10条回答
  •  一个人的身影
    2020-11-30 07:58

    It is possible to compare a compiled regular expression with 're._pattern_type'

    import re
    pattern = r'aa'
    compiled_re = re.compile(pattern)
    print isinstance(compiled_re, re._pattern_type)
    
    >>True
    

    Gives True, at least in version 2.7

提交回复
热议问题