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

#!/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>

你可能感兴趣的:([,python基础,])