Why is this regex not working?
import re
i="<wx._controls.Button; proxy of <Swig Object of type 'wxButton *' at 0x2d040b0> >"
m = re.match("controls(.*)[;]", i)
if m:
print m.group(1)
It returns nothing. I am trying to get everything in between, "controls" and ";" This solution works with other test cases however not with this one.
re.match
only matches at the beginning of the string. You want re.search
.
However, it looks like you're evaluating the result of repr
on an object to get the class name. Why not just use obj.__class__.__name__
instead? On use duck typing and avoid code specific to individual classes.