Python学习笔记--正则

#正则匹配nginx配置文件upstream整段

re.compile(r'upstreams*xxx.xx.coms*[^}]*+}')

#获取用户ip和组ip

user_uid = os.stat(conf_full_path).st_uid
user_gid = os.stat(conf_full_path).st_gid

#正则匹配nginx server配置
ip, port = '192.168.1.1', 80
del_pattern = re.compile(r's*servers*{0}:{1}[sS]*?;'.format(ip.replace('.', '\.'), port))
#正则匹配全部server
s*servers*[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}:[0-9]{1,4}[sS]*?;$
原文地址:https://www.cnblogs.com/lihuiyw/p/4632422.html