Check if a variable is SRE_Match

前端 未结 5 1727
自闭症患者
自闭症患者 2021-01-19 02:30

I need to check if a variable is a regular expression match object.

print(type(m)) returns something like that: <_sre.SRE_Match object at 0x000

5条回答
  •  野的像风
    2021-01-19 02:57

    You can do something like this

    isinstance(m, type(re.match("","")))
    

    Usually there is no need to check the type of match objects, so noone has bothered to make a nice way to do it

提交回复
热议问题