正则表达式

import re

#如果匹配成功,则打印m,否则返回Null
if re.match(r'[0-9]','a'):print 'm'
#用空格分割
 re.split(r'\s+', 'a b   c')
返回:['a', 'b', 'c', 'd']
#用逗号分隔
re.split(r'[\s\,]+', 'a,b, c  d')
返回:['a', 'b', 'c', 'd']

rr=re.match(r'[0-9]','3')

rr.group(0)

就可以在Match对象上用group()方法提取出子串来。

注意到group(0)永远是原始字符串,group(1)group(2)……表示第1、2、……个子串。

你可能感兴趣的:(正则表达式)