正则表达式
多个字符串拆分
import re def mySplit(str): print(re.split(r'[,;\t|]+', str)) mySplit('ab;cd|efg|hi,,jkl|mn\topq;rst,uvw\txyz')
捕获组
def myReplace(str): print(re.sub('(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})', r'\g<month>/\g<day>/\g<year>', str)) myReplace('2022-01-31 00:01:00 this is a new year!')
立志如山 静心求实
浙公网安备 33010602011771号