re正则表达式

#!\usr\bin\env\python

#  -*- coding:utf-8 -*9

import re

re.search("R[a-zR-Z]+a","Chen321RongAhua123aRonghua###")     #+a,匹配一段字符串结尾带a的字符串

结果为:Ronghua

 

re.search("(abc){2}(\|\|=){2}","alexabcabc||=||=")    #字符串分组

结果为:abcabc||

 

re.split("[0-9]+","abc12de3f45GH")     #匹配字符

结果为:['abc','de','f','GH']

 

re.findall("[0-9]{1,3}","aa1x2a3456aa")    #匹配数字

结果为::['1','2','345','6']

posted on 2018-08-15 18:59  凛冬08  阅读(101)  评论(0编辑  收藏  举报

导航