什么是python re.match函数?(实例解析)


当前第2页 返回上一页

1

(0, 3)None

1

2

3

4

5

6

7

8

9

10

# !/usr/bin/python

import re

line = "Cats are smarter than dogs"

matchObj = re.match(r'(.*) are (.*?) .*', line, re.M | re.I)

if matchObj:

    print "matchObj.group() : ", matchObj.group()

    print "matchObj.group(1) : ", matchObj.group(1)

    print "matchObj.group(2) : ", matchObj.group(2)

else:

    print "No match!!"

以上实例输出如下:

1

2

3

4

5

matchObj.group() :  Cats are smarter than dogs

 

matchObj.group(1) :  Cats

 

matchObj.group(2) :  smarter

以上就是本篇文章所讲述的所有内容,这篇文章主要介绍了python中re.match函数的相关知识,希望你能借助资料从而理解上述所说的内容。希望我在这片文章所讲述的内容能够对你有所帮助,让你学习python更加轻松。

更多相关知识,请访问php中文网Python教程栏目。

以上就是什么是python re.match函数?(实例解析)的详细内容,更多文章请关注木庄网络博客!!

返回前面的内容

相关阅读 >>

Python语言是干什么的

Python 解决中文写入excel时抛异常的问题

Python学会了可以干什么

selenium+Python如何爬取简书网站

Python中filecmp的简单使用

Python3.6.4如何安装到树莓派3代

Python库怎么安装

Python怎么做反爬

Python异常和错误有什么区别

Python中的排序操作和heapq模块的介绍(代码示例)

更多相关阅读请进入《Python》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...