I'm trying to use \w{2}\d/\d{1,2}(/\d{1,2})? in order to match the following two interfaces on a Cisco switch:
Gi1/0/1
Fa0/1
When I use re.search(), it returns the desired output.
import re port = "Gi1/0/1 Fa0/1" search = re.search(r'\w{2}\d/\d{1,2}(/\d{1,2})?', port) print search.group()
I get "Gi1/0/1" as the output.
When I use re.findall()
import re port = "Gi1/0/1 Fa0/1" search = re.findall(r'\w{2}\d/\d{1,2}(/\d{1,2})?', port) print search
I get "['/1', '']" which is undesired.
Why does't findall() return ['Gi1/0/1','Fa0/1']?
Is that because I used (/\d{1,2})?, and findall() is supposed to return this part? Why is that?
How do we get ['Gi1/0/1','Fa0/1'] using findall()?