Python Forum
Help with regex please - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Help with regex please (/thread-17320.html)



Help with regex please - mrapple2020 - Apr-06-2019

Hello, if possible can someone assist to draft the following regex. I could first retrieve everything after "Outgoing Interface" like I did below. Then match with something like (TenGigE(.......))+ to retrieve the interfaces. I believe there is a better way to do it though with just one regex, but I can't figure it out. Thank you.

#Objective: I need to retrieve "Outgoing Interface" value. In the example below TenGigE0/5/0/1.200, TenGigE0/3/0/1".
string = "[Incoming Interface List  TenGigE0/5/0/1.200 Flags: Outgoing Interface List  TenGigE0/5/0/1.201 Flags: F NS, Up: 01:06:23 blahblah TenGigE0/3/0/1 Flags:"
#I tried:
import re
match = re.findall(r'(?:Outgoing Interface)(.*)', string)
if match:
    #Got all Outgoing Interface output. Now retrieve interfaces:
    print(match)



RE: Help with regex please - mrapple2020 - Apr-07-2019

I think I found it. Here it is:
raw_int_data = olist_data[1].split('Outgoing Interface List')
    raw_int_out  = raw_int_data[1]
    match = re.findall(r'(TenGig[A-Za-z0-9\/\.]+)', raw_int_out)
    if match:
        print(f'Detected interface...{match}')