How to find a string using regex in Python 3?
textfile.txt
21/02/2018
23/02/2018
yes/2s20/2620 A/RB2
417 A/FOüR COT
Python code
import re
with open('textfile.txt','r') as f:
input_file = f.readlines()
b_list = []
for i in input_file:
s = re.findall(r'^(?=.*/F)(?:[^/\n]*/){1,}[^/\n]*$|^(?=.*A/RB2$)(?:[^/\n]*/){3,}[^/\n]*$',i)
if len(s) > 0:
print(s)
b_list.append(s)
print(b_list,"***********")
Expected Output:
yes/2s20/2620 A/RB2
417 A/FOüR COT