python里使用正则表达式的search()函数实现指定位置搜索
来源:互联网 发布:js按钮current trigger 编辑:程序博客网 时间:2024/05/21 18:41
前面学习过search()可以从任意一个文本里搜索匹配的字符串,也就是说可以从任何位置里搜索到匹配的字符串。但是现实世界很复杂多变的,比如限定你只能从第100个字符的位置开始匹配,100个字符之前的不要匹配,这样的需求怎么样实现呢?来看下面的例子,它就是指定位置开始搜索:
深入浅出Numpy
五子棋游戏开发
http://edu.csdn.net/course/detail/5487
#python 3.6#蔡军生 #http://blog.csdn.net/caimouse/article/details/51749579#import retext = 'This is some text -- with punctuation.'pattern = re.compile(r'\b\w*is\w*\b')print('Text:', text)print()pos = 0while 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
阅读全文
2 0
- python里使用正则表达式的search()函数实现指定位置搜索
- python里使用正则表达式搜索单词
- 函数实现指定位置搜索
- python里使用正则表达式的前向搜索或后向搜索模式
- python里使用正则表达式的前向搜索否定模式
- python里使用正则表达式的后向搜索否定模式
- python里使用正则表达式的后向搜索肯定模式
- python里使用正则表达式
- python正则表达式函数match()和search()的区别
- python里使用正则的findall函数
- python里使用正则的finditer()函数
- 正则表达式替换指定位置的字符串
- python里使用正则表达式的group()函数访问分组的结果
- python里使用正则表达式的groups()函数访问组匹配串
- dw里常用的搜索正则表达式
- python里使用正则表达式的转义字符的匹配
- python里使用正则表达式的重复模式
- python里使用正则表达式的非贪婪模式
- Spring MVC json基础工具类
- poj3254:Corn Fields(状压DP)
- Springboot系列:@SpringBootApplication注解
- keil C51 模拟堆栈,可重入函数调用,参数传递
- MySQL性能优化的最佳20+条经验
- python里使用正则表达式的search()函数实现指定位置搜索
- hdu1521排列问题
- 编辑距离算法(LD)详解
- JavaEE基础之冒泡排序
- Android性能优化的几个方面
- 远程连接Linux的相关配置
- 作者: 果冻虾仁 来源: CSDN 发布时间: 2017-08-10 23:08 阅读: 52608 次 推荐: 251
- masonry报'attempting to add unsupported attribute: (null)'
- 类似angularjs的ng-options解析规则的解析函数