对于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()
© 版权声明
THE END
暂无评论内容