0
import re
st = """interface GigabitEthernet0/0
 ip address 192.168.1.11 255.255.255.0
 duplex auto
 speed auto
 media-type rj45
!
interface GigabitEthernet0/1
 no ip address
 duplex auto
 speed auto
 media-type rj45
!
interface GigabitEthernet0/1.13
 encapsulation dot1Q 13
 ip address 155.1.13.1 255.255.255.0
 ipv6 address 2001:155:1:13::1/64
!"""
# t = re.compile(r"interface\s(.+)\n(?:.+\n)?\s?ip address\s(.+)",re.MULTILINE)
t = re.compile(r"""interface\s(.+)\n     #
                    (?:.+\n)?            #
                    \s?ip address\s(.+)  #
                    """,re.MULTILINE | re.VERBOSE)
res = t.findall(st)
print(res)
for line in res:
    print(f"{line[0].ljust(25)}: {line[1]}")

When i compile a regex pattern with multiple flags, a find wont return any result. Find with only multiline flags works fine. Where am I going wrong ?

I was expecting findall to return all regex matches.

ver_roh
  • 15
  • 3
  • 1
    What are you trying to match here? – Tim Biegeleisen Nov 08 '22 at 06:39
  • 2
    With `VERBOSE`, whitespace is ignored. If you need a whitespace, you should escape it, as in `ip\ address` – zvone Nov 08 '22 at 07:19
  • I expect [('GigabitEthernet0/0', '192.168.1.11 255.255.255.0'), ('GigabitEthernet0/1.13', '155.1.13.1 255.255.255.0')] which i get with the first regex which is commented. – ver_roh Nov 08 '22 at 07:38

0 Answers0