我想使用python RegEx在文本文件中进行搜索。.而不是只返回我的搜索字符串,它应该返回匹配的整个字符串
python 3.7
with open('movies.txt', 'w') as csv_file:
csv_writer = writer(csv_file)
headers = ['Title', 'Link']
csv_writer.writerow(headers)
for post in posts:
title = post.find('p').get_text()
link = post.find('a')['href']
csv_writer.writerow([title, link])
with open('movies.txt') as m1, open('movies.csv', 'w') as m2:
for line in m1:
movies = re.findall('th+', line)
m1.writelines(movie + '\n' for movie in movies)
如果文本文件中的文本为:**您无休止的是什么?势不可挡** 我搜索了'unst',它应该完整返回'unstopp'和' unstoppable'
而不是只返回我的搜索字符串,如果匹配则应该返回整个字符串