您的位置:首页 > 编程语言 > Python开发

python核心编程-正则表达式之-任意单个字符

2016-01-12 22:30 666 查看
#!/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>>>>>>>>>>>>>>

3.14

1>>>>>>>>>>>>>>

3x14

2>>>>>>>>>>>>>>

3.14

2>>>>>>>>>>>>>>

D:\Python27\test>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: