python 查找正则所有的匹配结果

python 查找正则所有的匹配结果:

'''查找第一个匹配结果'''
def regex_match_search(regex, data):
   result = re.search(regex, data, re.I|re.M|re.S)
   return result


'''查找所有的匹配结果'''
def regex_match_findall(regex, data):
   result = re.findall(regex, data, re.I|re.M|re.S)
   return result



if __name__ == '__main__':
   str = u"a\\(b\\)c"
   test = u"ssa(b)cddda(b)c"
   regex = u"(" + str + ")"
   matchObjs = regex_match_findall(regex, test)
   if matchObjs and len(matchObjs) > 0:
      for temp in matchObjs:
          print temp

 

参考:

http://blog.csdn.net/djskl/article/details/44357389

http://cache.baiducontent.com/c?m=9f65cb4a8c8507ed4fece7631046893b4c4380146d96864968d4e414c42246171f27bae53a715042889422301cf91e1ab9ab68332a0526b69ccd8940d6afd7756fde28763b5adc1c4ec419de8a11768171ca4de9de4dbce6a661cdf0&p=89769a47c5934eac58ee8712115585&newp=8267c80d95904ead08e2977e0e0896231610db2151d4db116b82c825d7331b001c3bbfb423241206d2c17e6406af435de0f637783c0021a3dda5c91d9fb4c57479&user=baidu&fm=sc&query=python+search+findall&qid=b94ee7e900016b51&p1=1

 

 

 

 

 

 

转载于:https://my.oschina.net/airship/blog/869795

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值