python里使用正则表达式的search()函数实现指定位置搜索
2017-10-17 17:22
1191 查看
前面学习过search()可以从任意一个文本里搜索匹配的字符串,也就是说可以从任何位置里搜索到匹配的字符串。但是现实世界很复杂多变的,比如限定你只能从第100个字符的位置开始匹配,100个字符之前的不要匹配,这样的需求怎么样实现呢?来看下面的例子,它就是指定位置开始搜索:
结果输出如下:
Text: This is some text -- with punctuation.
0 : 3 = "This"
5 : 6 = "is"
在这个例子里,实现一个低效的iterall()函数相同的功能。
深入浅出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 = re.compile(r'\b\w*is\w*\b') print('Text:', text) print() pos = 0 while True: match = pattern.search(text, pos) if not match: break s = match.start() e = match.end() print(' {:>2d} : {:>2d} = "{}"'.format( s, e - 1, text[s:e])) # Move forward in text for the next search pos = e
结果输出如下:
Text: This is some text -- with punctuation.
0 : 3 = "This"
5 : 6 = "is"
在这个例子里,实现一个低效的iterall()函数相同的功能。
深入浅出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使用正则表达式的search()函数实现指定位置搜索功能
- python3正则表达式简单使用、search()、match()等函数的区别
- python3正则表达式简单使用、search()、match()等函数的区别
- 使用正则表达式实现搜索关键字高亮显示
- python正则表达式模块,re.sub的函数使用
- python里使用正则表达式的group()函数访问分组的结果
- Python中正则表达式match()、search()函数及match()和search()的区别详解
- python里使用正则表达式的后向搜索否定模式
- python里使用正则表达式的后向搜索肯定模式
- python中,有关正则表达式re函数:compile、match、search、findall
- 使用正则表达式实现搜索关键字高亮显示
- python里使用正则表达式的前向搜索或后向搜索模式
- 使用Python正则表达式提取搜索结果中的站点
- python里使用正则表达式的前向搜索否定模式
- 函数实现指定位置搜索
- python里使用string.Template实现自定义转义字符和正则表达式替换
- python之正则表达式搜索和替换函数sub()与subn()
- python学习:python中的正则表达式函数match和search()的区别
- ASP.NET使用正则表达式实现搜索关键字高亮显示
- Python正则表达式中的 compile,search,group,groups 函数的简单说明