标签:match 文本 字符串 sdas aaa arc 表达式 find python
# -*- coding: utf-8 -*- import re #match :从字符串开头匹配字符串 , 如果配到了返回一个对象, 匹配不到返回None res = re.match("test.", "testasDwoedHello") print(res) #获取 匹配的字符串 print(res.group()) #从整个文本开始搜索 sr = re.search("D.+d", "testasDwoedHello") print(sr.group()) #返回所有 fa = re.findall("[0-9]{1,3}", "tesda123stasDwoe435dHello667Daasdd") print(fa) #分割 print(re.split("[0-9]","asdasd1dads222dasd21")) #替换 print(re.sub("[0-9]","aaa","wer1azx2vff22"))
标签:match 文本 字符串 sdas aaa arc 表达式 find python
原文地址:http://www.cnblogs.com/gaizhongfeng/p/7825028.html