Question
python regex to get text within a pattern defined
I'm working on writing a parser to extract information from the output given below
i need to get all the three texts which are in between '--'. so i wrote a regular expression as below
import re
def parse_ib_write_bw(mystr):
output = dict()
# match = re.search('--+\n(\n|.)*?--+', mystr, re.I)
match = re.search('--+\n(.*)--+(.*)--+(.*)--+', mystr, re.DOTALL)
if match:
print(match.groups(1))
print(match.groups(2))
print(match.groups(3))
parse_ib_write_bw(my_str)
My understanding is:
--+\n(.*)--+ --> This would give the output of the first block until second '---' is found
(.*)--+ --> would give the second block until the third '--' is found
(.*)--+ --> would give the third block until the final'--' is found
but i get the entire output. where i'm going wrong with my understanding?
3 52
3