I’m relatively new to python and writing a code to get to the next line after a python regex match.
I looked into the examples like https://regex101.com/r/dQ0gR6/1 and after match, get next line in a file using python bit could not achieve what i intend to capture.
My text is:
FlowRole SrcAddr DstAddr Proto SrcPort DstPort Key Type Vrf Dst Vrf Service Instance Session Id Src Local Dst Local CP Redirect NH type NH id
I 172.16.10.1 172.18.10.1 ICMP 21 2048 1 2 3 1 8389614 1 0 0 2 1
FlowRole SrcAddr DstAddr Proto SrcPort DstPort Key Type Vrf Dst Vrf Service Instance Session Id Src Local Dst Local CP Redirect NH type NH id
R 172.18.10.1 172.18.10.110 ICMP 21 0 1 3 2 1 8389614 0 1 0 2 1
The code that i used to match is:
FlowRole[^\n]+([\r\n]\w+) --> I;m able to match the line and the next line word but not the entire line..
need some help here.
I want to match the entire line after the pattern match
i.e., I want to match this these two lines:
I 172.16.10.1 172.18.10.1 ICMP 21 2048 1 2 3 1 8389614 1 0 0 2 1
R 172.18.10.1 172.18.10.110 ICMP 21 0 1 3 2 1 8389614 0 1 0 2 1
>Solution :
You were 90% of the way there, I Just changed the \w+ (which looks for only words characters but skips spaces) to [^\r\n] as you used previously to match the whole line) –
FlowRole[^\n]+[\r\n]([^\r\n]+)
This gives the expected output as per regex101