I have this sample data inside a text file:
09-02||||||||09-14|07:24|12:15|12:58| | |
09-03| | | | | | |09-15|||||||
I'am trying to get all the data with this kind of pattern and store it in an array or list:
\d{2,3}-\d{2,3}
the output data when printed should be like this:
['09-02','09-14','09-02','09-15']
I tried this code but it printed all the lines matching the pattern:
n_date = re.compile('\d{2,3}-\d{2,3}')
with open('sample_2.txt', 'r') as n:
for line in n:
re.match(n_date, line)
print(line)
Please give me an idea on how can I just get the data matching my regex pattern not the whole line. Thank you!
it printed all the linesBut you only haveprint(line)once, shouldn't it only be printing the last line?