python - Python中的正则表达式返回文本文件中的完整字符
问题描述
我想使用 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)
如果文本文件中的文本是:**你是什么势不可挡?unstoppable ** 我搜索了“unst”,它应该完整返回“unstopable”和“ unstoppable ”
如果匹配,它应该返回整个字符串,而不是只返回我的搜索字符串
解决方案
推荐阅读
- c - 将字符串从一个数组移动到另一个数组
- javascript - Javascript“声明但从未使用过的变量”......即使我正在使用它?
- python - python中子列表搜索的有效解决方案
- python - 如何在 Python 中创建多个构造函数?
- tomcat - 无法使用 Apache Tomcat 或作为独立服务器启动 jena fuseki
- android - 如何根据导出的模式 JSON 文件创建和填充房间数据库?
- powerbi - 在 DAX 中结合 SELECTCOLUMNS 和 ORDER BY
- python - 无法在谷歌云上部署服务
- javascript - 修改 Object.prototype.hasOwnProperty 方法导致网页崩溃
- javascript - Canopy javascript函数找不到元素