python里使用正则表达式的全匹配功能
2017-10-16 18:03
686 查看
前面学习了很多匹配,比如搜索任意位置的search()函数,搜索边界的match()函数,现在还需要学习一个全匹配函数,就是搜索的字符与内容全部匹配,它就是fullmatch()函数。例子如下:
#python 3.6
#蔡军生
#http://blog.csdn.net/caimouse/article/details/51749579
#
import re
text = 'This is some text -- with punctuation.'
pattern = 'is'
print('Text :', text)
print('Pattern :', pattern)
m = re.search(pattern, text)
print('Search :', m)
s = re.fullmatch(pattern, text)
print('Full match :', s)
text = 'is'
print('Text :', text)
s = re.fullmatch(pattern, text)
print('Full match :', s)
text = 'iss'
print('Text :', text)
s = re.fullmatch(pattern, text)
print('Full match :', s)
结果输出如下:
Text : This is some text -- with punctuation.
Pattern : is
Search : <_sre.SRE_Match object; span=(2, 4), match='is'>
Full match : None
Text : is
Full match : <_sre.SRE_Match object; span=(0, 2), match='is'>
Text : iss
Full match : None
深入浅出Numpy
五子棋游戏开发
http://edu.csdn.net/course/detail/5487
#python 3.6
#蔡军生
#http://blog.csdn.net/caimouse/article/details/51749579
#
import re
text = 'This is some text -- with punctuation.'
pattern = 'is'
print('Text :', text)
print('Pattern :', pattern)
m = re.search(pattern, text)
print('Search :', m)
s = re.fullmatch(pattern, text)
print('Full match :', s)
text = 'is'
print('Text :', text)
s = re.fullmatch(pattern, text)
print('Full match :', s)
text = 'iss'
print('Text :', text)
s = re.fullmatch(pattern, text)
print('Full match :', s)
结果输出如下:
Text : This is some text -- with punctuation.
Pattern : is
Search : <_sre.SRE_Match object; span=(2, 4), match='is'>
Full match : None
Text : is
Full match : <_sre.SRE_Match object; span=(0, 2), match='is'>
Text : iss
Full match : None
深入浅出Numpy
http://edu.csdn.net/course/detail/6149
Python游戏开发入门
http://edu.csdn.net/course/detail/5690你也能动手修改C编译器
http://edu.csdn.net/course/detail/5582纸牌游戏开发
http://edu.csdn.net/course/detail/5538
五子棋游戏开发
http://edu.csdn.net/course/detail/5487
RPG游戏从入门到精通
http://edu.csdn.net/course/detail/5246
WiX安装工具的使用
http://edu.csdn.net/course/detail/5207
俄罗斯方块游戏开发
http://edu.csdn.net/course/detail/5110
boost库入门基础
http://edu.csdn.net/course/detail/5029
Arduino入门基础
http://edu.csdn.net/course/detail/4931
Unity5.x游戏基础入门
http://edu.csdn.net/course/detail/4810
TensorFlow API攻略
http://edu.csdn.net/course/detail/4495
TensorFlow入门基本教程
http://edu.csdn.net/course/detail/4369
C++标准模板库从入门到精通
http://edu.csdn.net/course/detail/3324
跟老菜鸟学C++
http://edu.csdn.net/course/detail/2901
跟老菜鸟学python
http://edu.csdn.net/course/detail/2592
在VC2015里学会使用tinyxml库
http://edu.csdn.net/course/detail/2590
在Windows下SVN的版本管理与实战
http://edu.csdn.net/course/detail/2579
Visual Studio 2015开发C++程序的基本使用
http://edu.csdn.net/course/detail/2570
在VC2015里使用protobuf协议
http://edu.csdn.net/course/detail/2582
在VC2015里学会使用MySQL数据库
http://edu.csdn.net/course/detail/2672
相关文章推荐
- 详解python里使用正则表达式的全匹配功能
- python里使用正则表达式的词组匹配功能
- python里使用正则表达式的组匹配自引用
- python里使用正则表达式排除集合里字符的功能
- python里使用正则表达式来替换匹配成功的组
- python里使用正则表达式的转义字符的匹配
- python里使用正则表达式的限制边界功能
- python使用正则表达式替换匹配成功的组
- python中使用正则表达式匹配出字符串中的数字
- python使用正则表达式的search()函数实现指定位置搜索功能
- 在Python中使用正则表达式同时匹配邮箱和电话并进行简单的分类
- python里使用正则表达式来替换匹配成功的组名
- Python中使用中文正则表达式匹配指定的中文字符串
- python里使用正则表达式来替换匹配成功的组并限定替换的次数
- python里使用正则表达式来替换匹配成功的组并输出替换的次数
- python3.4学习笔记(十二) python正则表达式的使用,使用pyspider匹配输出带.html结尾的URL
- Python正则表达式非贪婪、多行匹配功能示例
- python使用正则表达式匹配字符串开头并打印示例
- python里使用正则表达式的组匹配是否成功之后再自引用
- 使用Python正则表达式RE从CSDN博客源代码中匹配出博客信息