python regex库实例用法总结
作者:十一 时间:2023-11-02 12:17:27
对于regex库的使用不难,因为本身就是python中自带的库,所以在调用上也是常见的库使用类型,大部分时候都是用于搜索上下文信息的,但是有些时候也会调用它的两个使用方法,其中一个是编译,另外一个是匹配,能够进行匹配的对象有很多,比如字符串,单一的字符等等,好啦,下面来详细看下使用吧。
调用实例:
from uregex import Regex_input
x=Regex_input('j','jd')
x.regex()
c=Regex_input('j','d')
c.regex()
编译实例:
for regex in regexes:
print 'seeking "%s" ->' % regex.pattern
if regex.search(text):
print 'match'
else:
print 'No match'
这两种方式都是常见的项目应用实例,大家可以浏览掌握住,对我们的项目实例还是非常有帮助的
Python Regex库的使用实例扩展
#!/usr/bin/python
import re
class Regex_input:
def __init__(self,task,source):
self.source=source
self.task=task
def regex(self):
opt=re.search(self.task,self.source)
if opt==None:
print 'No Found the task: %s' % self.task
else:
print '%s is in %d - %d' % (self.task,opt.start(),opt.end())
调用实例:
from uregex import Regex_input
x=Regex_input('j','jd')
x.regex()
c=Regex_input('j','d')
c.regex()
来源:https://www.py.cn/jishu/jichu/22459.html
标签:python,regex库
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python扩展库numpy入门教程
2022-05-05 14:28:05
Django在win10下的安装并创建工程
2021-10-12 18:54:57
![](https://img.aspxhome.com/file/2023/6/100846_0s.png)
前端图片懒加载的原理与3种实现方式举例
2024-04-17 10:20:02
![](https://img.aspxhome.com/file/2023/1/136311_0s.png)
js实现的牛顿摆效果
2024-04-29 13:25:45
浅谈Python 敏感词过滤的实现
2022-12-11 07:47:17
三种SQL分页法
2010-05-07 11:03:00
pycharm实现猜数游戏
2023-01-14 19:04:49
![](https://img.aspxhome.com/file/2023/5/67385_0s.jpg)
ASP文件中的安全问题
2011-04-14 11:15:00
Python 私有化操作实例分析
2022-11-06 05:44:42
![](https://img.aspxhome.com/file/2023/9/69049_0s.png)
python基础之多态
2022-04-05 10:06:06
![](https://img.aspxhome.com/file/2023/2/107462_0s.png)
php连接微软MSSQL(sql server)完全攻略
2023-07-16 17:56:43
![](https://img.aspxhome.com/file/2023/6/55426_0s.jpg)
分析mysql中一条SQL查询语句是如何执行的
2024-01-19 15:43:59
![](https://img.aspxhome.com/file/2023/8/96498_0s.jpg)
MySQL中基本的用户和权限管理方法小结
2024-01-24 20:03:49
perl控制流介绍(if条件,while,for循环,foreach)
2023-02-13 16:33:34
python3.x实现base64加密和解密
2023-12-17 00:30:33
简述:我为什么选择Python而不是Matlab和R语言
2021-05-13 06:51:27
![](https://img.aspxhome.com/file/2023/0/102980_0s.png)
Python3 如何开启自带http服务
2023-07-27 14:33:46
![](https://img.aspxhome.com/file/2023/1/63911_0s.jpg)
mysql alter table 修改表命令详细介绍
2024-01-13 21:35:38
用python统计代码行的示例(包括空行和注释)
2022-06-28 02:15:30
Python中namedtuple 命名元祖的使用
2023-02-20 15:06:00