(作者:玛瑙河,转载请注明作者或出处,) 

 字符串替换

1.替换所有匹配的子串

1#用newstring替换subject中所有与正则表达式regex匹配的子串
2result = re.sub(regex, newstring, subject)

2.替换所有匹配的子串(使用正则表达式对象)

1reobj = re.compile(regex)
2result = reobj.sub(newstring, subject)

 

字符串拆分

1.字符串拆分

1result = re.split(regex, subject)


2.字符串拆分(使用正则表示式对象)

1reobj = re.compile(regex)
2result = reobj.split(subject)
posted on 2005-08-29 20:27  玛瑙河  阅读(13651)  评论(0编辑  收藏  举报