use*_*159 2 python regex wxwidgets wxpython
为什么这个正则表达式不起作用?
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)
Run Code Online (Sandbox Code Playgroud)
它什么都不返回.我试图让一切介于两者之间,"控制"和";" 此解决方案适用于其他测试用例,但不适用于此测试用例.
re.match仅匹配字符串的开头.你想要的re.search.
但是,看起来您正在评估repr对象的结果以获取类名.为什么不直接使用obj.__class__.__name__呢?使用duck typing并避免特定于各个类的代码.