一、字符串匹配
import re
#匹配IP地址
ip_v4 = "14.19.19.19"
ip_v4_reg = "^((25[0-5]|2[0-4]\\d|[1]{1}\\d{1}\\d{1}|[1-9]{1}\\d{1}|\\d{1})($|(?!\\.$)\\.)){4}$"
if re.match(ip_v4_reg,ip_v4):
print("match ok")
else:
print("match filed")
二、字符串分割
import re
#用不可见字符分割字符串
str_test = "a b bb c"
str_reg = r"\s+"
result_str = re.split(str_reg,str_test)
print(result_str)