码迷,mamicode.com
首页 > 编程语言 > 详细

Python学习笔记--正则

时间:2015-07-09 10:57:03      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:

#正则匹配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]*?;$

 

Python学习笔记--正则

标签:

原文地址:http://www.cnblogs.com/lihuiyw/p/4632422.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!