Code show as below, but there is a problem: "255.255.255.256" will be processed into "255.255.255.25"
import re
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?)")
def get_ip_by_regex(ip_str):
"""Match IP from the given text and return
:param ip_str: like "255.255.255.255,255.255.255.256,260.255.255.255"
:type ip_str: string
:return: IP LIST ["255.255.255.255"]
:rtype: list[string]
"""
ret = []
for match in ip_pattern.finditer(ip_str):
ret.append(match.group())
return ret
If I pass the 255.255.255.255,255.255.255.256,260.255.255.255 string I expect ["255.255.255.255"] as the results.