我想在我的网页中查找 6 位数字:
<td style="width:40px;">705214</td>
我的代码是:
s = f.read()
m = re.search(r'\A>\d{6}\Z<', s)
l = m.group(0)
最佳答案
如果您只想查找 >
之间的 6 位数字和<
符号,使用以下正则表达式:
import re
s = '<td style="width:40px;">705214</td>'
m = re.search(r'>(\d{6})<', s)
l = m.groups()[0]
注意括号的使用(
和)
表示一个捕获组。
关于python - 对 Python 中的正则表达式模式感到困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9426043/