我试图在一个文本文件中找到一个字符串的多个实例,但我只能找到第一个实例的方法。我试过各种各样的while和for循环都没有用,我被困在答案中。在python中实现这一点的最有效方法是什么?在
movinf = open("movinf.txt", "a")
match = re.search('"string":([^,]+)', name)
if match:
result = match.group(1)
movinf.write(result + "\n")
else:
pass
movinf.close()
Tags:
你可以试试re.findall()
以下程序使用简单的文件和列表操作:
只运行一次块,因此只得到一个结果。使用
re.findall
代替:相关问题 更多 >
编程相关推荐