Python Forum

Full Version: Help with regex please
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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)
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}')