当前第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的join怎么用
Python文件读写保存操作的实现代码
Python定制类__str__(实例详解)
Python如何实现字符串去重操作的代码示例
Python爬虫可以自学吗
Python gui编程(tkinter)是什么?实例展示Python tkinter教程
Python笔试题之设计“跳一跳”小游戏计分器
Python怎么样输出九九乘法表
Python如何读取 .ini 格式文件(代码)
Python实现读写excel和修改excel的代码
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » python使用正则表达式实现搜索单词的示例代码