正则表达式

多个字符串拆分

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!')

 

posted on 2022-05-29 12:16  溪水静幽  阅读(10)  评论(0)    收藏  举报