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

python核心编程-正则表达式之-匹配多个字符串

2016-01-12 22:17 871 查看
#!/usr/bin/env python
# -*- coding: UTF-8 -*-

import re

bt = 'bat|bet|bit'
m = re.match(bt,'bat')
if m is not None:
print m.group()
print '1>>>>>>>>>>>>>>'

m = re.match(bt,'blt')
if m is not None:
print m.group()
print '2>>>>>>>>>>>>>>'

m = re.match(bt,'He bit me!')
if m is not None:
print m.group()
print '3>>>>>>>>>>>>>>'

m = re.search(bt,'He bit me!')
if m is not None:
print m.group()
print '4>>>>>>>>>>>>>>'


输出:

D:\Python27\test>re03.py

bat

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

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

3>>>>>>>>>>>>>>

bit

4>>>>>>>>>>>>>>

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