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.
.match() looks from the beginning. You want .search().
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