ip = "192.168.18.152"
#截取IP段前两段
ip1 = str(re.findall(r'(?<!d)d{1,3}.d{1,3}(?=.d)', ip)[0])
print(ip1)
#截取IP段中间两段
ip2 = re.findall(r'(?<=d.)d{1,3}.d{1,3}(?=.d)', ip)[0]
print(ip2)
#截取IP段后两段段
ip3 = re.findall(r'(?<=d.)d{1,3}.d{1,3}(?!d|.)', ip)[0]
print(ip3)
#截取IP段第三段
ip4 = str(re.findall(r'(?<=d.)d{1,3}.d{1,3}(?!d|.)', ip)[0]).split('.')[0]
print(ip4)
#截取IP段最后段
ip5 = str(ip).split('.')[-1]
print(ip5)