Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get a next line after a match using python regex

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading