這篇文章將為大家詳細(xì)講解有關(guān)regex庫如何在python中使用 ,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個(gè)參考,希望大家閱讀完這篇文章后對(duì)相關(guān)知識(shí)有一定的了解。
調(diào)用實(shí)例:
from uregex import Regex_input x=Regex_input('j','jd') x.regex() c=Regex_input('j','d') c.regex()
編譯實(shí)例:
for regex in regexes: print 'seeking "%s" ->' % regex.pattern if regex.search(text): print 'match' else: print 'No match'
這兩種方式都是常見的項(xiàng)目應(yīng)用實(shí)例,大家可以瀏覽掌握住,對(duì)我們的項(xiàng)目實(shí)例還是非常有幫助的
#!/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())
調(diào)用實(shí)例:
from uregex import Regex_input x=Regex_input('j','jd') x.regex() c=Regex_input('j','d') c.regex()
關(guān)于regex庫如何在python中使用 就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。