NO.27 re
来源:互联网 发布:域名注册好了怎么使用 编辑:程序博客网 时间:2024/05/17 07:08
#!/usr/bin/env python# -*- coding:utf-8 -*-# @Time : 2017/11/8 22:38# @author : hezefan# @file : 11.1.py'''常用正则表达式'''#https://regex101.com/ 一个正则匹配网站import timeitprint timeit.timeit(setup='''import re; reg = re.compile('<(?P<tagname>\w*)>.*</(?P=tagname)>')''', stmt='''reg.match('<h1>xxx</h1>')''', number=1000000)print timeit.timeit(setup='''import re''', stmt='''re.match('<(?P<tagname>\w*)>.*</(?P=tagname)>', '<h1>xxx</h1>')''', number=1000000)#结果:0.375981021608# 0.934127292757#解释:timeit.timeit是用来统计程序执行的时间的,和明显第一个print的执行时间要比第二个的执行时间快好多,这个就是把正则表达是表示成正则对象最明显的好处。下面我们就可以看看如何把正则表达式转换成正则对象
#!/usr/bin/env python# -*- coding:utf-8 -*-# @Time : 2017/11/15 22:11# @author : hezefan# @file : 11.2.pyimport rereg = re.compile(r'abc.*')print(type(reg))print(reg)
阅读全文
0 0
- NO.27 re
- No。28 re方法
- re 中 报错 no such group
- RE
- re
- re
- RE
- re
- re
- re
- re
- re
- re
- Re
- re
- re
- RE
- re
- day-11
- thinkphp5 静态资源文件引入
- 简图记录-linux文件系统基础
- Vulkan规范:第八章 8.3 ~ 8.10
- Jmeter使用笔记
- NO.27 re
- leetcode习题解答:10. Regular Expression Matching
- JAVA基础面试(二)
- Vulkan规范:第八章 8.11 ~ 8.13
- seo优化中怎么做聚合页-优秀聚合页参考
- 在React的Redux中,如何方便的查看next state的状态?
- Vulkan规范:第九章
- 【推荐系统】概率矩阵分解 probabilistic matrix factorization
- C#初识8 多态之接口(interface)