really sorry for the stupid question, I am not a programmer, just a network admin. Could you please help me with correct re.findall expression to do the following: I have to extract an exact phrase from a text string.
Phrase to Match: " host 192.168.72.2 " (whitespaces matter)
Sample text:
access-list inside extended permit tcp object-group DM_INLINE_NETWORK_555 host 192.168.72.2 object-group DM_INLINE_TCP_35
As input re.findall gets a variable. If I try to parse something simple, like this:
object network H_Lin_US01
host 192.168.72.2
this works fine for me:
kon = []
kon.append("host "+IP_to_search)
kon2 = "host "+IP_to_search
for counter, entry in enumerate(logfile):
entry=entry[1:] #this cuts whitespace before "host" word
match = re.findall("%s\s*$" % kon2, entry)
if match == kon:
It returns exactly "host x.x.x.x " with whitespace in the end.
I need now to return almost the same, but with any prepending text in the beginning + one whitespace before, like " host 1.1.1.1 ". It seems I've tried all possible options here but it still doesn't work as expected. Many many thanks in advance!