如何使用正则表达式在python3中的特定字符串之前或之后找到一行?我正在阅读文本文件中的内容,请帮助我
文件.txt
my name is dharshini
my mom name is chandra
my dad name is uday
my anniversay is on 04/01/1997
import re
with open('file.txt','r') as f:
input_file = f.readlines()
for line in input_file :
find_line = re.findall(r'(mom)', line)
print(next-1(line))
print(next(line))
print(next(line))
预期输出:
my name is dharshini
my dad name is uday
my anniversay is on 04/01/1997
波斯汪
Helenr
相关分类