我有一个像下面这样的字符串,我想得到两个数字“28”和“1”,但现在我只能通过我的代码得到“28”。请帮帮我。你知道吗
import re
content="""<span class="lineNum"> 28 </span><span class="lineCov"> 1 : get_pid_file(const char *file, pid_t *pid)</span>"""
pattern = "(\d+)"
ret = re.search(pattern,content)
if ret:
print "find: %s" % ret.group()
使用^{}
但你可能想缩小你的正则表达式。你知道吗
编辑:
您可能需要将正则表达式更改为
r"<span.*?>.*?(\d+).*?</span>"
的某种变体,以便只匹配span标记中的数字。你知道吗相关问题 更多 >
编程相关推荐