1
2
3
4
|
re. compile (strPattern[, flag]):
这个方法是Pattern类的工厂方法,用于将字符串形式的正则表达式编译为Pattern对象。
第二个参数flag是匹配模式,取值可以使用按位或运算符 '|' 表示同时生效,比如re.I | re.M。
另外,你也可以在regex字符串中指定模式,比如re. compile ( 'pattern' , re.I | re.M)与re. compile ( '(?im)pattern' )是等价的。
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
xxx.com文件内容
$TTL 600 ; 1 day
@ IN SOA ns1.xxxx.com. root.xxxx.com.(
1002766 ; Serial
3600 ; Refresh (1 hour)
900 ; Retry (15 minutes)
3600000 ; Expire (5 weeks 6 days 16 hours)
3600 ; Minimum (1 hour)
)
@ 2D IN NS ns1.xxxx.com.
@ 2D IN NS ns2.xxxx.com.
$ORIGIN xxxx.com.
;;
IN MX 5 mxbiz1.qq.com.
IN MX 10 mxbiz2.qq.com.
IN TXT "v=spf1 include:spf.mail.qq.com ~all"
auth IN MX 5 mail.pub.jumei.com.
auth IN TXT "v=spf1 ip4:x.x.x.x/24 ip4:x.x.x.x/24 ~all"
stk IN CNAME office.reemake.net.
signontest IN CNAME xxx.xxxx.com.
qqmaile33f7f2c IN CNAME mail.qq.com.
*.kbs IN A 192.168.20.222
flow IN A 192.168.49.10
maven IN A 192.168.49.9
auth IN A 192.168.49.11
auth IN A 192.168.49.12
lynx-auth IN A 192.168.49.13
lynx-auth IN A 192.168.49.14
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
import sys
import re
import os
if __name__ = = '__main__' :
content = []
with open ( 'xxx.com' , 'r' ) as f:
with open ( 'xxx.com.bak' , 'w' ) as g:
for content in f.readlines():
x = sys.argv[ 1 ].strip()
p = re. compile (r '^' + x + r '\s.+IN\s.+A' )
if not p.match(content):
g.write(content)
os.rename( 'xxx.com.bak' , 'xxx.com' )
o = sys.argv[ 1 ].strip()
v = sys.argv[ 2 ].strip()
q = sys.argv[ 3 ].strip()
g.write( "%s\tIN\tA\t%s\n" % (o,v))
g.write( "%s\tIN\tA\t%s\n" % (o,q))
|
1
2
3
4
5
6
7
8
|
636,637d635
< auth IN A x.x.x.x
< auth IN A x.x.x.x
801a800,801
> auth IN A 192.168.6.69
> auth IN A 192.168.6.80
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
wms.web
wms.rf
wms.worker
report.web
report.worker
admin
invoice.web.center
invoice.worker.center
invoice.web. cd
invoice.worker. cd
jlsext
jls
jlsworker
uds
udsworker
separate
|
本文转自谢无赖51CTO博客,原文链接:http://blog.51cto.com/xieping/1899918 ,如需转载请自行联系原作者