fork download
  1. import re
  2.  
  3. ip_pattern = re.compile(r"(?<![^,])(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)(?![^,])")
  4.  
  5. def get_ip_by_regex(ip_str):
  6. """Match IP from the given text and return
  7.  
  8. :param ip_str: like "255.255.255.255,255.255.255.256,260.255.255.255"
  9. :type ip_str: string
  10. :return: IP LIST ["255.255.255.255"]
  11. :rtype: list[string]
  12. """
  13. return ip_pattern.findall(ip_str)
  14.  
  15. print(get_ip_by_regex('255.255.255.255,255.255.255.256,260.255.255.255'))
Success #stdin #stdout 0.03s 9564KB
stdin
Standard input is empty
stdout
['255.255.255.255']