赞
踩
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import re
anyend = '.end'
m = re.match(anyend,'bend')
if m is not None:
print m.group()
print '1>>>>>>>>>>>>>>'
anyend = '.end'
m = re.match(anyend,'\nend')
if m is not None:
print m.group()
print '2>>>>>>>>>>>>>>'
anyend = '.end'
m = re.search(anyend,'The end.')
if m is not None:
print m.group()
print '3>>>>>>>>>>>>>>'
print '-------------------'
patt314 = '3.14'
pi_patt = '3\.14'
m = re.match(pi_patt, '3.14')
if m is not None:
print m.group()
print '1>>>>>>>>>>>>>>'
m = re.match(patt314, '3x14')
if m is not None:
print m.group()
print '2>>>>>>>>>>>>>>'
m = re.match(patt314, '3.14')
if m is not None:
print m.group()
print '2>>>>>>>>>>>>>>'
输出:
D:\Python27\test>re04.py
bend
1>>>>>>>>>>>>>>
2>>>>>>>>>>>>>>
end
3.14
1>>>>>>>>>>>>>>
3x14
2>>>>>>>>>>>>>>
3.14
2>>>>>>>>>>>>>>
D:\Python27\test>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。