re.split(pattern, string, maxsplit=0, flags=0)
pattern:匹配的字符串
string:需要切分的字符串
maxsplit:分隔次数,默认为0(即不限次数...re.split()切割功能非常强大
>>> import re
>>> line = 'aaa bbb ccc;ddd eee,fff'
>>> line
'aaa bbb ccc;ddd eee...,fff'
单字符切割
>>> re.split(r';',line)
['aaa bbb ccc', 'ddd eee,fff']
两个字符以上切割需要放在 [ ] 中
>>> re.split(...r'[;,]',line)
['aaa bbb ccc', 'ddd eee', 'fff']
所有空白字符切割
>>> re.split(r'[;,\s]',line)
['aaa', 'bbb'...:…)的形式指定
>>> re.split(r'(?