def print_re():
#p = re.compile(r'hello')
#p = re.compile(r'he')
#m = p.match('hello,wrold')
#print m.group()
print '========='
m1 = re.match(r'zheng','zhenghangjj')
print m1.group()
print '=====yi===='
p = re.compile(r'\d+')
r = p.split('one1two2shtee3four4')
print r
#['one', 'two', 'shtee', 'four', '']
#p1 = re.compile('one1two2shtee3four4')
p = re.compile(r'\d+')
print p.findall('one1two2shtee3four4five5')
#['1', '2', '3', '4', '5']
def print_sub():
'''
>> > re.sub('[abc]', 'o', 'Mark')
'Mork'
>> > re.sub('[abc]', 'o', 'rack')
'rook'
>> > re.sub('[abc]', 'o', 'caps')
'oops'
>> >
# >>> re.sub('[abc]','o','mastash',1)
'mostash'
>>>
'''
本文转自 知止内明 51CTO博客,原文链接:http://blog.51cto.com/357712148/2045805,如需转载请自行联系原作者