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 0x000000000345BE68>
but when I import _sre
and try to execute type(m) is SRE_Match
the exception NameError: name 'SRE_Match' is not defined
is raised.
You can do
SRE_MATCH_TYPE = type(re.match("", ""))
at the start of the program, and then
type(m) is SRE_MATCH_TYPE
each time you want to make the comparison.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With