正则-分割/替换

##以匹配符号切割list

import re

s = 'afd4afagf4dgsh'
b = re.split('4', s)
print(b)#['afd', 'afagf', 'dgsh']

##以匹配符号切割,在以符号连接成str

import re

s = 'afd4afagf4dgsh'
b = re.sub('4', '*', s)
print(b)#afd*afagf*dgsh

 

posted @ 2019-11-19 13:16  chenlulu1122  阅读(102)  评论(0)    收藏  举报