[root@localhost /]# cat strduiqi.py
#!/bin/python
import re
log=open('/var/log/pacman.log').read()
print re.sub('(\d{4})-(\d{2})-(\d{2})',r'\2/\3/\1',log)
[root@localhost /]#
捕获组命名
[root@localhost /]# cat strduiqi.py
#!/bin/python
import re
a=open('./tuned/tuned.log').read()
print re.sub('(\d{4})-(\d{2})-(\d{2})',r'\2/\3/\1',a)
print re.sub('(?P\d{4})-(?P\d{2})-(?P\d{2})','\g/\g/\g',a)
[root@localhost /]#
[root@localhost /]#
阅读(2586) | 评论(0) | 转发(0) |