python 正则小例子

 1 import  re
 2 
 3 s1 = '1 (021)8567895 90'
 4 s2 = '1 021-5689564 90'
 5 s3 = '1 021 4886542 90'
 6 s4 = '1 0218567899 90'
 7 s5 = 'module-layout=\"layout-d\">\n  \n \n\n<link '
 8 s6 = 'module-layout=\"layout-d\n<link '
 9 m1 = re.findall(r'\(\d{3}\)\d{7,8}',s1)
10 m2 = re.findall(r'\d*-\d{7,8}',s2)
11 m3 = re.findall(r'\d{2,3}[ -]?\d{1,10}',s4)
12 m5 = re.findall(r'module-layout=.*',s6,re.S)#re.S 让  .  匹配换行符

 

posted @ 2016-11-27 21:14  恰似少年  阅读(178)  评论(0编辑  收藏  举报