将SRE_Match对象转换为字符串

时间:2014-04-12 03:00:00

标签: python

re.search的输出返回<_sre.SRE_Match object at 0x10d6ed4e0>我想知道如何将其转换为字符串?或者更易读的形式?

3 个答案:

答案 0 :(得分:21)

你应该这样做:

result = re.search(your_stuff_here)
if result:
    print result.group(0)

答案 1 :(得分:3)

如果您想按顺序查看所有群组:

result = re.search(your_stuff_here)
if result:
    print result.groups()

答案 2 :(得分:1)

<_ sre.SRE_Match对象; span =(0,54),match =“''>使用resuilt.group(0),但有一个新问题是AttributeError:'NoneType'对象没有属性'group'