fork(1) download
  1. import re
  2.  
  3. def find_ips(inp):
  4. '''
  5. Returns a list of ip addresses of the form 'x.x.x.x' that are in the input
  6. string and are separated by at least some whitespace.
  7. >>> find_ips('this has one ip address 127.0.0.1')
  8. ['127.0.0.1']
  9. >>> find_ips('this has zero ip addresses 1.2.3.4.5')
  10. []
  11. '''
  12. pattern = r"^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$"
  13. iplist = [match[0] for match in re.findall(pattern, inp)]
  14. return iplist
  15.  
  16. ips = []
  17. ips = find_ips('basjlcbndilsfn 1.2.3.4.5')
  18. print ips
  19.  
Success #stdin #stdout 0.02s 7216KB
stdin
Standard input is empty
stdout
[]