A personal project requiring me to create regular expressions for IP addresses led me to the following standoff.
pattern = r'123\.145\.167\.[0-9]{1,2}'
source = "123.145.167.0, 123.145.167.99, 123.145.167.100"
n = re.search(pattern, source)
print n.group()
pattern = r'123\.145\.167\.[0-9]{1,2}'
source = "123.145.167.0, 123.145.167.99, 123.145.167.100"
n = re.compile(pattern)
print n.findall(source)
While using search matches only the first element in the source string, findall creates a problem by giving an output such as this
['123.145.167.0', '123.145.167.99', '123.145.167.10']
Is it possible that I can obtain the matches for both 123.145.167.0 and 123.145.167.99 and not the 123.145.167.100 ?
I have already gone thorough python - regex search and findall and yet not able to understand how I can solve my problem.