Suppose I have a line like this:
from rw-sc-22 (wellknown [94.26.18.9]) How can I get an IP address out of it using Python tools without reinventing the bike?
Suppose I have a line like this:
from rw-sc-22 (wellknown [94.26.18.9]) How can I get an IP address out of it using Python tools without reinventing the bike?
regular expression
import re
str = "from rw-sc-22 (wellknown [94.26.18.9])"
result = re.search ('\ [(\ d + \. \ d + \. \ d + \. \ d +) \]', str)
print result.group (1)
From this line, the simplest method is:
mystr = "from rw-sc-22 (wellknown [94.26.18.9])" mystr.split("[")[1].split("]")[0] Source: https://ru.stackoverflow.com/questions/556668/
All Articles