Python 将 SRE_Match 对象转换为字符串
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23025565/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 02:08:25 来源:igfitidea点击:
Convert SRE_Match object to string
提问by Liondancer
The output of my re.search
returns <_sre.SRE_Match object at 0x10d6ed4e0>
I was wondering how could I convert this to a string? or a more readable form?
我re.search
返回的输出我<_sre.SRE_Match object at 0x10d6ed4e0>
想知道如何将其转换为字符串?或更易读的形式?
采纳答案by sshashank124
You should do it as:
你应该这样做:
result = re.search(your_stuff_here)
if result:
print result.group(0)
回答by JOM
If you want to see all groups in order:
如果要按顺序查看所有组:
result = re.search(your_stuff_here)
if result:
print result.groups()