Python Regex库的使用

今天开始学习Python标准库,同时复习前面所学的。
该脚本实现的功能是通过类来调用,并搜索指定上下文,

#!/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.cnblogs.com/xiaoCon/p/2951999.html