Reputation: 17
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.
Upvotes: 0
Views: 32