Issue
I am using the below if condition and regular expression to search for an IP address in a file,It will search for the IP address that has the space at the end for example: 192.168.x.x , however it is not searching for the IP address which is present in this format 192.168.x.x/32 because it does not have the space at the end, it has a "/" character
How can i modify the search condition to include both the variations in the output
if (re.match('(.+) ' +host_ipaddress+ ' (.+)', line)):
Solution
if (re.match('(.+) ' +host_ipaddress+ '(\/\d+) (.+)', line)):
or
if (re.match('(.+) ' +host_ipaddress+ '(\/\d{1,2}) (.+)', line)):
if you want to be more precise.
Though ideally, you shouldn't need to require (.+)
and the beginning or end of your expression.
Answered By - dhalsim2
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.