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

python核心编程-正则表达式之-创建字符集合

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

import re

m = re.match('[cr][23][dp][o2]','c3po')
if m is not None:
print m.group()
print '1>>>>>>>>>>>>>>'

m = re.match('[cr][23][dp][o2]','c2do')
if m is not None:
print m.group()
print '2>>>>>>>>>>>>>>'

m = re.match('r2d2|c3po','c2do')
if m is not None:
print m.group()
print '3>>>>>>>>>>>>>>'

m = re.match('r2d2|c3po','r2d2')
if m is not None:
print m.group()
print '4>>>>>>>>>>>>>>'


输出:

D:\Python27\test>re05.py

c3po

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

c2do

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

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

r2d2

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

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