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]))
Found "this" in "http://blog.csdn.net/caimouse is great, this is great way!" from 40 to 44 ("this")
在这里使用 start() 表示匹配的开始位置,end()表示结束位置。
总结
以上就是python使用正则表达式实现搜索单词的示例代码的详细内容,更多请关注Gxl网其它相关文章!
查看更多关于python使用正则表达式实现搜索单词的示例代码的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did84416