当前第2页 返回上一页
示例代码
1 2 3 4 5 6 7 8 9 10 11 12 | import re
pattern = 'this'
text = 'http://blog.csdn.net/caimouse is great, this is great way!'
match = re.search(pattern, text)
s = match.start()
e = match.end()
print ( 'Found "{}"\nin "{}"\nfrom {} to {} ("{}")' . format (
match.re.pattern, match.string, s, e, text[s:e]))
|
结果输出如下:
1 2 3 | Found "this"
in "http://blog.csdn.net/caimouse is great, this is great way!"
from 40 to 44 ( "this" )
|
在这里使用start()
表示匹配的开始位置,end()表示结束位置。
总结
以上就是python使用正则表达式实现搜索单词的示例代码的详细内容,更多文章请关注木庄网络博客!!
返回前面的内容
相关阅读 >>
Python脚本如何输入成绩求平均分?
Python取余运算符是什么?
Python求解物理学中的双弹簧质能系统的代码实例
Python os.chroot() 方法定义以及作用详解(实例)
Python如何安装wordcloud库
Python全栈要学什么
Python和go之间的区别是什么?
Python实现des加密解密的方法介绍(代码)
Python字典怎么排序
request timeout是什么意思
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » python使用正则表达式实现搜索单词的示例代码