I have following raw text output that I need to extract selective information but my regex in python does not pick up the selective information. My string is:
label 123 start
int
some other random text
exit
exit
label 576 start
int
some other random text
exit
exit
label 888 start
explanation jgfjgjgj
some random text
exit
up up
exit
label 902 start
explanation jgfjgjgj
some random text
exit
up up
exit
label 456 start
explanation jgfjgjgj
some random text
exit
up up
exit
From the above the text string I would like to capture following items as individual items
Item 1
label 888 start
explanation jgfjgjgj
some random text
exit
up up
exit
Item 2
label 902 start
explanation jgfjgjgj
some random text
exit
up up
exit
Item 3
label 456 start
explanation jgfjgjgj
some random text
exit
up up
exit
I have following regex:
(label)\s\d{1,4}(.*?)(?=\s*explanation)(.*?)\s+up up
That also captures following two items which I do not want:
label 123 start
start
some other random text
exit
exit
label 576 start
start
some other random text
exit
exit
I have constructed based on the basis that it does a lookahead for word "explanation" and only capture the items starting at label and finishing at 'up up'. The first item it captures all of label 123 and label 576. The lookahead i thought should have stopped it but it captures it.
` tags?
– Barmar May 19 '17 at 02:36