正则re模块

1. re模块的使用过程

    #coding=utf-8

    # 导入re模块
    import re

    # 使用match方法进行匹配操作
    result = re.match(正则表达式,要匹配的字符串)

    # 如果上一步匹配到数据的话,可以使用group方法来提取数据
    result.group()

2. re模块示例(匹配以itcast开头的语句)

    #coding=utf-8

    import re

    result = re.match("itcast","itcast.cn")

    result.group()

运行结果为:

itcast

3. 说明

  • re.match() 能够匹配出以xxx开头的字符串
posted @ 2019-07-18 06:27  GeorgeXu  阅读(175)  评论(0编辑  收藏  举报