我正在使用python脚本在文本文件中运行。
我想在文本文档中搜索一个img标签,并将标签作为文本返回
当我运行regex re.match(行)它返回一个_sre.SRE_MATCH对象。
我如何得到它返回一个字符串?
import sys
import string
import re
f = open("sample.txt", 'r' )
l = open('writetest.txt', 'w')
count = 1
for line in f:
line = line.rstrip()
imgtag = re.match(r'',line)
print("yo it's a {}".format(imgtag))
运行时打印:
yo it's a None
yo it's a None
yo it's a None
yo it's a <_sre.sre_match object at>
yo it's a None
yo it's a <_sre.sre_match object at>
yo it's a None
yo it's a <_sre.sre_match object at>
yo it's a <_sre.sre_match object at>
yo it's a None
yo it's a None