I am trying a dynamic regex pattern whose occurrence is not known, for instance
ip = '3.3.3.5'
stt ="""
(1.1.1.1/32, 3.3.3.5/32), abcd: xx:xx:xx, abv cd
value: eth1/1 , bbcc , time: tt:tt
text :
eth1/1 ip time <<
eth1/2 ip time <<
"""
what i need to retrieve is , based on the ip i need to get the interface , in the above example , for 3.3.3.5/32 ip , i want to get the interface under "text:" which is eth1/1 and eth1/2
Regex i have used :
re.findall(ip+"[\/0-9,)]+\s+abcd: xx:xx:xx, abv cd\s+value: [0-9a-zA-Z\/]+ , bbcc , time: tt:tt\s+ values text\s+[0-9a-zA-Z\/]+",stt)
output : ['3.3.3.5/32), abcd: xx:xx:xx, abv cd\n value: eth1/1 , bbcc , time: tt:tt\n values text\n eth1/1']
It returns the first occurrence which is eth1/1, but i am not aware how to get both the interfaces, pls guide
1.1.1.1/32? Additionally, use the newerregexmodule which supports\G.