python 正则小例子

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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(rmodule-layout=.*,s6,re.S)#re.S 让  .  匹配换行符

 

以上是关于python 正则小例子的主要内容,如果未能解决你的问题,请参考以下文章