title: How do I select short Cisco interface names with RegEx in Python?
body: <p>I am trying to select shortened Cisco interface names as shown below, from CDP as well as show mac address-table output using Python with RegEx.</p>
  
  <p>I have tried a RegEx tester and Gig\s?\d+(/\d+)* seems to work great, but it does not work in my Python code. It seems a little lacking, even when I try to escape the forward-slash, which I get varying opinions on via RegEx documentation.</p>
  
  <p>DEVICENAME       Gig 2/0/45        136              R T   AIR-CAP35 Gig 0</p>
  
  <p>DEVICENAME       Gig 2/0/47        158              R T   AIR-CAP35 Gig 0</p>
  
  <p>DEVICENAME       Gig 1/0/1         174             R S I  CISCO2921 Gig 0/1</p>
  
  <p>DEVICENAME       Gig 3/0/1         151             R S I  CISCO2921 Gig 0/1</p>
  
  <p>For inputs such as Gig 3/0/1 above I get matches that look like /1, /2, etc. Please help with what I am missing and an explanation of what Python is doing to my RegEx would be greatly appreciated!</p>
  
  <p>I have tried various RegEx such as Gig\s?\d+ and it starts to work, but won't capture the extended name. When I start adding on, such as Gig\s?\d+/\d+/\d+ it works fantastic, but it will not handle names without 3 sets of numbers, such as on a 4500 where they will be more like Gig 4/30. When I add the grouping to optionally add the /\d+ for interfaces further down in a line-card stack, such as on a 3750 the RegEx quickly falls apart between what I can validate in a tester vs. through Python.</p>
  
  <p>If I double-group the last part such as Gig\s?\d+((/\d+)*) it no longer captures the first part, which is really throwing me off.</p>