python核心编程-正则表达式之-边界匹配
2016-01-13 22:13
761 查看
#!/usr/bin/env python # -*- coding: UTF-8 -*- import re #在开头 m = re.search('^The', 'The end.') if m is not None: print m.group() print '1>>>>>>>>>>>>>' #不在开头 m = re.search('^The', 'end. The') if m is not None: print m.group() print '2>>>>>>>>>>>>>' #\b匹配边界词 m = re.search(r'\bthe', 'bite the dog') if m is not None: print m.group() print '3>>>>>>>>>>>>>' m = re.search(r'\bthe', 'bitethe dog') if m is not None: print m.group() print '4>>>>>>>>>>>>>' #\B 是 \b的反义词 m = re.search(r'\Bthe', 'bitethe dog') if m is not None: print m.group() print '5>>>>>>>>>>>>>'
输出:
D:\Python27\test>re07.py
The
1>>>>>>>>>>>>>
2>>>>>>>>>>>>>
the
3>>>>>>>>>>>>>
4>>>>>>>>>>>>>
the
5>>>>>>>>>>>>>
D:\Python27\test>
相关文章推荐
- [Python标准库]calendar——处理日期
- python有关的书签
- Python 2.5.12 匿名函数
- 关于《selenium2自动测试实战--基于Python语言》
- python实现堆排序
- 使用国内镜像源来加速python pypi包的安装
- 在python下安装这个第三方库numpy、scipy、matplotlib
- Python 2.5.11 返回函数
- Python---索引
- python动态生成写文件变量
- Win7 python2.7 Scrapy的安装
- python基础知识-列表,元组,字典
- Python在IDLE环境下常用快捷键
- numpy的argsort和sum和tile函数
- python学习之3 数据库sqlite
- Python垃圾回收机制详解
- 【Python】Python中中文的字符串格式化对齐
- python学习之2 正则表达式re
- python---购物扩展
- python学习笔记 - 初识socket