Python学习笔记--正则

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

re.compile(r'upstream\s*xxx.xx.com\s*[^}]*+\}')

#获取用户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*server\s*{0}:{1}[\s\S]*?;'.format(ip.replace('.', '\\.'), port))
#正则匹配全部server
\s*server\s*[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}:[0-9]{1,4}[\s\S]*?;$

 

posted @ 2015-07-09 10:37  呜呼哀哉嘎嘣脆  阅读(144)  评论(0编辑  收藏  举报