Type of compiled regex object in python

后端 未结 10 1086
一个人的身影
一个人的身影 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条回答
  •  旧时难觅i
    2020-11-30 08:00

    >>> import re
    >>> regex = re.compile('foo')
    >>> regex
    <_sre.SRE_Pattern object at 0x10035d960>
    

    Well - _sre is a C extension doing the pattern matching...you may look in the _sre C source.

    Why do you care?

    Or you try something like this (for whatever reason - I don't care):

    >>> regex1 = re.compile('bar')
    >>> regex2 = re.compile('foo')
    >>> type(regex1) == type(regex2)
    True
    

提交回复
热议问题